Handling Dropdownlist inside gridview
Often there is a need to handle OnSelectedIndexChanged event of a dropdown residing inside a GridView. This can be handled as following:
1. Specify an event handler from dropdown in ASPX
1. Specify an event handler from dropdown in ASPX
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList OnSelectedIndexChanged="ddl_Change" DataTextField="UserName" AutoPostBack="true" DataValueField="userId" ID="ddl" runat="server"/>
2. Add event handler in ASPX.cs
Protected Sub ddl_Change(ByVal sender As Object, ByVal e As EventArgs)
'You can retrieve Dropdown as:
Dim DropDownControl As DropDownList = CType(sender, DropDownList)
'You can retrieve Parent GridRow as:
Dim gridRow As GridViewRow = CType(CType(sender, DropDownList).NamingContainer, GridViewRow)
' Do stuff with your dropdown and grid row like populating other dropdown. End Sub
Comments
Post a Comment