dropdown list in gridview does not seem to display correct data

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.
 
E

Eliyahu Goldin

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
 
P

Paul

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top