VB .Net - ASP too

Wednesday, December 21, 2005

Using a control template in datagrid

OK so you want to add a dropdown list to select values for editing data. The first thing you need to do is create the template column. In visual studio you can convert a field to a template while in edit fields mode. once you do this you should have something like the following:

<asp:templatecolumn headertext="columnheader">

<ItemTemplate>
<asp:label id="LabelName" runat="server" Text='<%# Container.dataitem("tempfield") %>'>
</asp>
</ItemTemplate>

<EditItemTemplate>
<asp:dropdownlist id="ddl1" runat="server" datavaluefield="Datavalue" datatextfield="DataDisplay" datasource="sqldatasource" >
</asp:dropdownlist>
</EditItemTemplate>

</asp:TemplateColumn>

the codebehind will look like this wherever you decide to put the code:

'declare variables to hold data
dim templist as DropDownList
dim tempdata as string

'assign the control as the control from the datagrid
templist = e.item.findcontrol("ddl1")
tempdata = templist.SelectedItem.Value

'if using sqldatasource assign the parameter
sqldatasource.updateparameter.item("data").defaultvalue = tempdata

Of course I haven't tested this yet but when I do I will make updates.

For a better understanding read the article by 4guysfromrolla at this link:
http://www.4guysfromrolla.com/webtech/050801-1.2.shtml

1 Comments:

  • My brother recommended I would possibly like this blog.

    He was totally right. This put up truly made
    my day. You can not consider simply how a lot time I had spent
    for this information! Thanks!

    my blog post :: modern outdoor furniture

    By Anonymous Anonymous, at 4/16/2013 9:37 PM  

Post a Comment

<< Home