Set value of dropdown list in datagrid

Discussion in 'ASP .Net Web Controls' started by Eric J., Jul 16, 2004.

  1. Eric J.

    Eric J. Guest

    I have a datagrid with a column containing a label and a dropdown (for the edit mode). When I choose edit, the dropdown should select the value corresponding to the label. Now it always selects the first item in the list.
    I have no idea where I can put code for this. I tried without success in the OnEdit handler, but I cannot set the value of the dropdown list there.

    Any suggestions?

    --
    Eric J. van Dorp
    VanDorp Educatief
    www.vandorp.net
    Eric J., Jul 16, 2004
    #1
    1. Advertising

  2. maybe because you did not put your code inside IsPostBack checking. so
    when you select the item in list server reloads the page with initialize
    data with your slections. do include inside checking like this

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    If IsPostBack = False Then
    Dim Con As New SqlConnection(strConnectionString)
    Dim cmd As New SqlCommand("Select MovID, MovTitle FROM
    Movie", Con)
    Con.Open()
    Dim drMovie As SqlDataReader = cmd.ExecuteReader

    With ddlMovie
    .DataSource = drMovie
    .DataTextField = "MovTitle"
    .DataValueField = "MovID"
    .DataBind()
    .Items.Insert(0, "<-- Select -->")

    End With
    Con.Close()
    End If

    End Sub

    Hope this helps

    Thusith


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Thusith Kathaluwage, Jul 25, 2004
    #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. Jenna Alten
    Replies:
    6
    Views:
    13,433
    Joe Fallon
    Feb 26, 2005
  2. vishnu
    Replies:
    1
    Views:
    1,189
    Patrick.O.Ige
    Mar 25, 2006
  3. Paul
    Replies:
    3
    Views:
    999
  4. M. Craig

    How to set background color of List item in dropdown list

    M. Craig, Nov 12, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    276
    M. Craig
    Nov 12, 2003
  5. mcauliffe
    Replies:
    5
    Views:
    330
    Billy
    Jan 26, 2007
Loading...

Share This Page