Template Field in gridview that fires drop down selected index changed event getting row index
I have a template field in the item template of a gridview. The template field is a status dropdownlist that fires an onindexchanged event for the drop down. I need to reference the row index of the row that fired the drop down on index changed.
Nothing chages in the gridview so I cant reference the datakey, or use the row event args cause it is a template field off of the item template. No row is selected, so is there a way to get that information his way???
Please help
Protected Sub drpStatus_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Dim strStatus as String = sender.SelectedValue Dim strID as String = Gridiew1.SelectedRow.Items.cells(0) or something like Dim strID as String = GridView1.SelectedDataKey End Sub
If you need the index then you should be able to cast the sender as a dropdownlist and grab the selectedindex
Dim ddl As DropDownList = CType(sender, DropDownList)
dim theindex as int32 = ddl.SelectedIndex
wolfcoop
ASKER
No I need the row index, not the selected index of the drop down. I can get that by sender.selectedindex. I need to reference the Row index so I know what ID to update in the DB with the new status value from the drop down. In other words I eitherneed to reference the first cell in the row that held the drop down that fired the onselectedindexchanged event, who ate the spider to eat the fly.
cdaly33
Sorry for the misread the first time. If it was me I'd go a bit different direction with it. I'd do a javascript function that calls a PageMethod which fires when the drop down fires and passes both the row index and selected value. Let me know if this is a possibility for your app.
Dim ddl As DropDownList = CType(sender, DropDownList)
dim theindex as int32 = ddl.SelectedIndex