S
sqlboy2000
All,
I have a simple datagrid with one column being a template column that
contains a dropdown control. I'd like to be able capture when the
index of the dropdown changes and access the value that has been
selected. I've tried the datagrid's itemcommand event but it doesn't
fire when the dropdown selection changes. Here is the closest solution
I could come up with using the onchange event:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim oDD As DropDownList = e.Item.FindControl("cboChoose")
oDD.Attributes.Add("onchange", "alert('" &
oDD.SelectedItem.Text & "');")
End If
End Sub
The only problem is, the SelectedItem.text value in the "alert" is
being generated as each column is bound, so it's always returning the
initial value. Anyone have any ideas on how to properly manage a
dropdown changed event within a template column? This seems like it
shouldn't be difficult, but several google searches have yielded
nothing.
Thanks.
I have a simple datagrid with one column being a template column that
contains a dropdown control. I'd like to be able capture when the
index of the dropdown changes and access the value that has been
selected. I've tried the datagrid's itemcommand event but it doesn't
fire when the dropdown selection changes. Here is the closest solution
I could come up with using the onchange event:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim oDD As DropDownList = e.Item.FindControl("cboChoose")
oDD.Attributes.Add("onchange", "alert('" &
oDD.SelectedItem.Text & "');")
End If
End Sub
The only problem is, the SelectedItem.text value in the "alert" is
being generated as each column is bound, so it's always returning the
initial value. Anyone have any ideas on how to properly manage a
dropdown changed event within a template column? This seems like it
shouldn't be difficult, but several google searches have yielded
nothing.
Thanks.