dropdown list in gridview does not seem to display correct data

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

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.
 
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
 
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 said:
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 said:
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.
 
Back
Top