Day drop down list in GridView

Discussion in 'ASP .Net' started by Diego, Jul 15, 2005.

  1. Diego

    Diego Guest

    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.
    Diego, Jul 15, 2005
    #1
    1. Advertising

  2. Diego

    KatB Guest

    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


    *** Sent via Developersdex http://www.developersdex.com ***
    KatB, Jul 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    752
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,009
    weiwei
    Jan 5, 2007
  3. Andy
    Replies:
    1
    Views:
    700
  4. msimmons
    Replies:
    0
    Views:
    470
    msimmons
    Jul 16, 2009
  5. Replies:
    5
    Views:
    266
Loading...

Share This Page