Which row in datagrid is being selected?
-
Hi, I have a datagrid with some boundcolumns and one templatecolumn. In the template column, i added a dropdownlist. Now on my page, i created a function to handle the SelectedIndexChanged event of the dropdownlist. And so far I am able to trap the event.
Protected Sub MyDropdownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Dim dpl as DropdownList ' How to determine which row's dropdown list did user select? nIndex = 0 dpl = CType(MyDataGrid.Items(nIndex).Cells(7).FindControl("MyDropdownList"), DropDownList) ' Do something with dpl End Sub
The problem (as stated in the comment above) is how do I know which row's dropdown list the user selected? I tried to use the selectedindex of the datagrid, but it seems to store garbage values. Thanks -
Hi, I have a datagrid with some boundcolumns and one templatecolumn. In the template column, i added a dropdownlist. Now on my page, i created a function to handle the SelectedIndexChanged event of the dropdownlist. And so far I am able to trap the event.
Protected Sub MyDropdownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Dim dpl as DropdownList ' How to determine which row's dropdown list did user select? nIndex = 0 dpl = CType(MyDataGrid.Items(nIndex).Cells(7).FindControl("MyDropdownList"), DropDownList) ' Do something with dpl End Sub
The problem (as stated in the comment above) is how do I know which row's dropdown list the user selected? I tried to use the selectedindex of the datagrid, but it seems to store garbage values. ThanksHi there, To access the
DataGridItem
object containing the DropDownList, you can do as below: + You first cast the sender object to theDropDownList
type to obtain the reference to the DropDownList. + You then cast theNamingContainer
property of the DropDownList object to theDataGridItem
type. You now have the reference to theDataGridItem
instance. -
Hi there, To access the
DataGridItem
object containing the DropDownList, you can do as below: + You first cast the sender object to theDropDownList
type to obtain the reference to the DropDownList. + You then cast theNamingContainer
property of the DropDownList object to theDataGridItem
type. You now have the reference to theDataGridItem
instance.A million thanks to you. I'd never find that out on my own. Guess I need to read up on MSDN library more. Thanks once again