Day drop down list in GridView

  • Thread starter Thread starter Diego
  • Start date Start date
D

Diego

I have a GridView linked to an ObjectDataSource, when I am in edit mode I'd
like to display a dropdownList with the name of the days and when i save the
changes I'd like to store 0 for sunday 1 for monday ecc ecc
Do you know how can I do it?
Thanks, Diego.
 
If I understand your question correctly, on the ItemDataBound event you
could do something like this:

If e.Item.ItemType = ListItemType.EditItem Then

'look for the ddlWeekDay dropdown
Dim ddlWeekDay As DropDownList =
CType(e.Item.FindControl("ddlWeekDay"), DropDownList)

'populate the dropdown values
Dim mySortedList As New System.Collections.SortedList
Dim Item As DictionaryEntry

mySortedList("0") = "Sunday"
mySortedList("1") = "Monday"
mySortedList("2") = "Tuesday"
mySortedList("3") = "Wednesday"

For Each Item In mySortedList
Dim newListItem As New ListItem
newListItem.Text = Item.Value
newListItem.Value = Item.Key
ddlWeekDay.Items.Add(newListItem)
Next

'set the current value held in the database
Dim currentWeekDay As String =
DataBinder.Eval(e.Item.DataItem, "WeekDay")
Dim li As ListItem =
ddlWeekDay.Items.FindByValue(currentWeekDay.ToString())
If Not (li Is Nothing) Then
li.Selected = True
End If


Hope this helps.
Kat
 
Back
Top