set the DropDownList to have AutoPostBack="true"and have event handler for its SelectedIndexChanged event (e.g
<asp:DropDownList ID="ddl1" ...OnSelectedIndexChanged="DropDownListGrd_SelectedIndexChanged" />...)E.g same event handler method for all the DDLs in the GridView.
In the SelectedIndexChanged you can get to the current GridViewRow with a code such as this.
Protected Sub DropDownListGrd_SelectedIndexChanged(sender As Object,e As EventArgs)
Dim currentddl As DropDownList=DirectCast(sender,DropDownList)
Dim currGrdRow As GridViewRow = DirectCast(currentddl.NamingContainer, GridViewRow)
'Do something with the DDL and GridViewRow
End Sub
E.g trick is just to be aware how control hierarchy goes within a
GridView. If you have reference to the DropDownList which raised the event, and you do, since that's standard in .Net Framework that sender argument provides this, you get the
GridViewRow it's located in via NamingContainer property.
joteke
All-Star
46284 Points
6896 Posts
ASPInsiders
MVP
Re: using a drop down list to trigger a 'select' within a grid view control
Jan 21, 2006 06:40 AM|LINK
Hi,
set the DropDownList to have AutoPostBack="true"and have event handler for its SelectedIndexChanged event (e.g <asp:DropDownList ID="ddl1" ...OnSelectedIndexChanged="DropDownListGrd_SelectedIndexChanged" />...)E.g same event handler method for all the DDLs in the GridView.
In the SelectedIndexChanged you can get to the current GridViewRow with a code such as this.
Protected Sub DropDownListGrd_SelectedIndexChanged(sender As Object,e As EventArgs)
Dim currentddl As DropDownList=DirectCast(sender,DropDownList)
Dim currGrdRow As GridViewRow = DirectCast(currentddl.NamingContainer, GridViewRow)
'Do something with the DDL and GridViewRow
End Sub
E.g trick is just to be aware how control hierarchy goes within a GridView. If you have reference to the DropDownList which raised the event, and you do, since that's standard in .Net Framework that sender argument provides this, you get the GridViewRow it's located in via NamingContainer property.
Teemu Keiski
Finland, EU