dropdown list in gridview does not seem to display correct data

Discussion in 'ASP .Net' started by Paul, Jul 2, 2008.

  1. Paul

    Paul Guest

    I have a gridview and in the RowDataBound I have the line of code below. I
    have the ObjDtaSce= to the datasource of a dropdown box. I have 3 rows that
    are populated and for some reason the dropdown box for all rows is populated
    by values expected in the last row only. I checked the ID value and it is
    correct for each row. Is there something I would need to reset?

    protected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)
    '''
    '''

    ObjDtaSce.SelectParameters["ID"].DefaultValue =Convert.ToString
    (integervariable);//
    thanks.

    --
    Paul G
    Software engineer.
     
    Paul, Jul 2, 2008
    #1
    1. Advertising

  2. You seem to be databinding declaratively with DataSourceID property. In this
    case actual select operation takes place in the PreRender event which fires
    well after all your RowDataBound events. You need to databind in the
    RowDataBound event itself. Simply databind with the DataSource property
    instead of DataSourceID and call myDdl.DataBind() method.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Paul" <> wrote in message
    news:...
    >I have a gridview and in the RowDataBound I have the line of code below. I
    > have the ObjDtaSce= to the datasource of a dropdown box. I have 3 rows
    > that
    > are populated and for some reason the dropdown box for all rows is
    > populated
    > by values expected in the last row only. I checked the ID value and it is
    > correct for each row. Is there something I would need to reset?
    >
    > protected void gridview_RowDataBound(object sender, GridViewRowEventArgs
    > e)
    > '''
    > '''
    >
    > ObjDtaSce.SelectParameters["ID"].DefaultValue =Convert.ToString
    > (integervariable);//
    > thanks.
    >
    > --
    > Paul G
    > Software engineer.
     
    Eliyahu Goldin, Jul 3, 2008
    #2
    1. Advertising

  3. Paul

    Paul Guest

    Re: dropdown list in gridview does not seem to display correct dat

    Thanks that worked! I removed the datasourceID that was set in the
    properties box and then just set the datasource and executed a databind as
    shown below.

    (e.Row.Cells[2].FindControl("dropdown2") as DropDownList).DataSource =
    ObjDtaSce;
    (e.Row.Cells[2].FindControl("dropdown2") as DropDownList).DataBind();
    --
    Paul G
    Software engineer.


    "Eliyahu Goldin" wrote:

    > You seem to be databinding declaratively with DataSourceID property. In this
    > case actual select operation takes place in the PreRender event which fires
    > well after all your RowDataBound events. You need to databind in the
    > RowDataBound event itself. Simply databind with the DataSource property
    > instead of DataSourceID and call myDdl.DataBind() method.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Paul" <> wrote in message
    > news:...
    > >I have a gridview and in the RowDataBound I have the line of code below. I
    > > have the ObjDtaSce= to the datasource of a dropdown box. I have 3 rows
    > > that
    > > are populated and for some reason the dropdown box for all rows is
    > > populated
    > > by values expected in the last row only. I checked the ID value and it is
    > > correct for each row. Is there something I would need to reset?
    > >
    > > protected void gridview_RowDataBound(object sender, GridViewRowEventArgs
    > > e)
    > > '''
    > > '''
    > >
    > > ObjDtaSce.SelectParameters["ID"].DefaultValue =Convert.ToString
    > > (integervariable);//
    > > thanks.
    > >
    > > --
    > > Paul G
    > > Software engineer.

    >
    >
    >
     
    Paul, Jul 3, 2008
    #3
    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.

Share This Page