Getting the SelectedIndex of a DropDownlist under the ItemTemplate in a
GridView is harder than I thought it would be.
I have:
A Gridview of n rows bound to a DataSet.
A DropDownList as an ItemTemplate in the GridView populated with three
ListItems.
A Button to Submit the form.
The desired outcome is for the user to make selections in the
dynamically generated DropDownLists in the rows fo the GridView and
submit the form.
Based on the SelectedIndex values of the DropDownLists the appopriate
code will be executed.
Unfortunately, the user can select an item from the DropDownList in
each row, but there is no SelectedIndexChanged event associated with
the dynmaically created DropDownLists, although the event is defined in
the tag and exists in the codebehind for the control named under the
ItemTemplate.
The DropDownlists are not in the ViewState, although the ViewState
property on the control named under the ItemTemplate is enabled.
I would like to find a way includ the SelectedIndex values of the
DropDownLists when the form is submitted.
If this can't be done directly, I'd like to find a way to hook up an
event to the DropDownLists so I can use the FindControl to return the
SelectedIndex and write it to an elemnt in the form.
I've gone through numerous approaches from Delegates to Event
Bubbling, after reading countless recommendations.
I could achieve my objective using client-side scripting, but am trying
to do things the .Net way now.
Any help would be appreciated.
Thanks
Dan