gridview dropdown autopostback value

R

rmccinc

I have a dropdownlist in a datagrid and it has autopostback set to
true. I need to get the new value of that dropdown to fill a textbox in
the same datagrid row. I have set the databind event on the gridview to
fire on pageload (including postbacks) because I need to change the
value of the textbox at each of the dropdownlists autopostback event. I
am using the OnItemDataBound event of the gridview to grab the
selectedvalue of the dropdownlist and set the textbox. Any help would
be appreciated. Thanks.

<asp:datagrid id="dg" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:DropDownList runat="server" id="dd"
AutoPostBack="true">
<asp:ListItem Value="1" Text="1"></asp:ListItem>
<asp:ListItem Value="2" Text="2"></asp:ListItem>
<asp:ListItem Value="3" Text="3"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox runat="server" id="tb"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>


Sub dgTransactions_ItemBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles dg.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

Dim tb As TextBox = CType(e.Item.FindControl("tb"), TextBox)
Dim dd As DropDownList = CType(e.Item.FindControl("dd"),
DropDownList)

'**************************
' dd.SelectedValue ia always 1
tb.Text = dd.SelectedValue
'**************************
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top