ParadiddleJohnny
New member
- Joined
- Oct 30, 2008
- Messages
- 1
- Programming Experience
- 1-3
I have an editable GridView that pulls data from a relational SQL DB. When the user wants to edit a row, I have a list box to appear in one of the editable columns. What I'd like to do is have the default value in the list box be the current value of the column. However, whenever the list box appears it defaults to the top of the list.
I was able to find some code that does what I want for a DataGrid and I reproduce that code below:
Ideally, I would like something similar that works on a GridView. I've been searching for quite a while and am stumped. Any assistance would be much appreciated.
I was able to find some code that does what I want for a DataGrid and I reproduce that code below:
VB.NET:
Private Sub ItemDataBound(ByVal sender As Object, ByVal e As DataGridIvemEventArgs)
If (e.Item.ItemType = ListItemType.EditItem) Then
Dim drv As DataRowView = CType(e.Item.DataItem,DataRowView)
Dim oldCategory As String = drv("Category").ToString
Dim ddl As ListBox = CType(e.Item.FindControl("Category"),ListBox)
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.FindByText(oldCategory))
End If
End Sub
Ideally, I would like something similar that works on a GridView. I've been searching for quite a while and am stumped. Any assistance would be much appreciated.