Day drop down list in GridView

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.
 
K

KatB

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top