gridview control, trying to set selected value in a dropdown list

Discussion in 'ASP .Net' started by Paul, Jun 26, 2008.

  1. Paul

    Paul Guest

    I have a gridview control with a template column that has a dropdown list.
    I am trying to set the selected value with the code below but it does not
    seem to work. It runs ok, no error but the value "minor" is not showing up
    as selected, any ideas, thanks.

    (e.Row.Cells[3].FindControl("drdnSeveritygv") as DropDownList).SelectedValue
    = "minor";
    --
    Paul G
    Software engineer.
    Paul, Jun 26, 2008
    #1
    1. Advertising

  2. Paul

    Teemu Keiski Guest

    Hi,

    at which point in code (Page_Load, Prerender, Button's click,RowDataBound
    etc) are you trying to do this? Is it sure that databinding doesn't clear it
    e.g that you set it first and call DataBind() immediately after?

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net

    "Paul" <> wrote in message
    news:...
    >I have a gridview control with a template column that has a dropdown list.
    > I am trying to set the selected value with the code below but it does not
    > seem to work. It runs ok, no error but the value "minor" is not showing
    > up
    > as selected, any ideas, thanks.
    >
    > (e.Row.Cells[3].FindControl("drdnSeveritygv") as
    > DropDownList).SelectedValue
    > = "minor";
    > --
    > Paul G
    > Software engineer.
    Teemu Keiski, Jun 26, 2008
    #2
    1. Advertising

  3. Paul

    Paul Guest

    Re: gridview control, trying to set selected value in a dropdown l

    Hi it is in the rowdatabound event. The actual code is

    (e.Row.Cells[2].FindControl("ddrlist") as DropDownList).SelectedValue =
    Convert.ToString(discSubCatnew.ID);
    discSubCatnew.ID = an integer and this integer corresponds to the data value
    field in the dropdown. Would you have to set it after you call databind?

    --
    Paul G
    Software engineer.


    "Teemu Keiski" wrote:

    > Hi,
    >
    > at which point in code (Page_Load, Prerender, Button's click,RowDataBound
    > etc) are you trying to do this? Is it sure that databinding doesn't clear it
    > e.g that you set it first and call DataBind() immediately after?
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    > "Paul" <> wrote in message
    > news:...
    > >I have a gridview control with a template column that has a dropdown list.
    > > I am trying to set the selected value with the code below but it does not
    > > seem to work. It runs ok, no error but the value "minor" is not showing
    > > up
    > > as selected, any ideas, thanks.
    > >
    > > (e.Row.Cells[3].FindControl("drdnSeveritygv") as
    > > DropDownList).SelectedValue
    > > = "minor";
    > > --
    > > Paul G
    > > Software engineer.

    >
    >
    >
    Paul, Jun 26, 2008
    #3
  4. Paul

    Paul Guest

    Re: gridview control, trying to set selected value in a dropdown l

    I got it working, had a typo in the dropdown list data value field, thanks!
    --
    Paul G
    Software engineer.


    "Teemu Keiski" wrote:

    > Hi,
    >
    > at which point in code (Page_Load, Prerender, Button's click,RowDataBound
    > etc) are you trying to do this? Is it sure that databinding doesn't clear it
    > e.g that you set it first and call DataBind() immediately after?
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    > "Paul" <> wrote in message
    > news:...
    > >I have a gridview control with a template column that has a dropdown list.
    > > I am trying to set the selected value with the code below but it does not
    > > seem to work. It runs ok, no error but the value "minor" is not showing
    > > up
    > > as selected, any ideas, thanks.
    > >
    > > (e.Row.Cells[3].FindControl("drdnSeveritygv") as
    > > DropDownList).SelectedValue
    > > = "minor";
    > > --
    > > Paul G
    > > Software engineer.

    >
    >
    >
    Paul, Jun 26, 2008
    #4
    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. Scott Allen
    Replies:
    1
    Views:
    855
    Scott Allen
    Aug 25, 2004
  2. Jenna Alten
    Replies:
    6
    Views:
    13,432
    Joe Fallon
    Feb 26, 2005
  3. Andy Sutorius

    how to get selected value from dropdown list

    Andy Sutorius, Mar 15, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    82,245
    raouf2me
    Oct 29, 2012
  4. =?Utf-8?B?SklNLkgu?=

    Q: dropdown list, no selected value

    =?Utf-8?B?SklNLkgu?=, Apr 12, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    608
    Eliyahu Goldin
    Apr 12, 2005
  5. vishnu
    Replies:
    1
    Views:
    1,187
    Patrick.O.Ige
    Mar 25, 2006
Loading...

Share This Page