Avatar of wolfcoop
wolfcoop
 asked on

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

Open in new window

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
wolfcoop

8/22/2022 - Mon
cdaly33

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
wolfcoop

ASKER
sure so you have sample code?  Basically that is exactly what I need.
cdaly33

Can you have a static drop down or is the drop down loaded from a database?  Either way it would be at least tomorrow until I have code.

the procedure is going to be like this and the only variable is what fires the initial call
http://www.geekzilla.co.uk/View30F417D1-8E5B-4C03-99EB-379F167F26B6.htm
ASKER CERTIFIED SOLUTION
wolfcoop

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.