cant get dropdown list bound to data in template column of gridvie

P

Paul

Hi I have a generic list of data
list <type> listcategory;
listcategory = new list <type>;
I also have a dropdown box that I have put into a template column of a
gridview.
I was able to populate the dropdown box ok when it was outside of the gridview

for (int i = 0; i <= listcategory.Count - 1; i++)
{
ddl.Items.Add(listcategory.Description);
}

Now that the control is in the gridview, ddl is not recognized.

I tried the following event but it does not seem to be reaching it.
protected void gridview_RowDataBound(object sender, DataGridItemEventArgs e)
{
;
}
I also tried the template edit from the gridview properties but could not
see how to bind the dropdown box to the items listcategory.Description.
Thanks.
 
L

Lee Thorpe

Paul

You need to use FindControl within your RowDataBound event-handler, i.e.

protected void gridview_RowDataBound(object sender, DataGridItemEventArgs e)
{
DropDownList ddl = e.Row.Cells[columnIndex].FindControl("ddl") as
DropDownList;

if (ddl != null)
{
// Databind, or populate ListItems in a loop.
}

}
 
L

Lee Thorpe

Paul

You need to use FindControl within your RowDataBound event-handler, i.e.

protected void gridview_RowDataBound(object sender, DataGridItemEventArgs e)
{
DropDownList ddl = e.Row.Cells[columnIndex].FindControl("ddl") as
DropDownList;

if(ddl != null)
{
// Databind, or populate ListItems in a loop.
}
}
 
P

Paul

thanks that worked!. Just had an additional question, I need the grid to
have 2 dropldown boxes but want the other fields to be two empty text box
columns for data entry, and a checkbox column for bool entry as well as a
final row count column,(just displays the row count). I had to bind the grid
to results of a dataset just to get the grid to show up so it currently has
extra undesired data from this dataset. Should I just create an empty
dataset and bind it to so a single row with two dropdowns and the other
fields discribed above show up?
Also I noticed there is no way to add a new row within the control, so
guessing this might have to be done outside the control.
Paul G
Software engineer.


Lee Thorpe said:
Paul

You need to use FindControl within your RowDataBound event-handler, i.e.

protected void gridview_RowDataBound(object sender, DataGridItemEventArgs e)
{
DropDownList ddl = e.Row.Cells[columnIndex].FindControl("ddl") as
DropDownList;

if(ddl != null)
{
// Databind, or populate ListItems in a loop.
}
}


Paul said:
Hi I have a generic list of data
list <type> listcategory;
listcategory = new list <type>;
I also have a dropdown box that I have put into a template column of a
gridview.
I was able to populate the dropdown box ok when it was outside of the
gridview

for (int i = 0; i <= listcategory.Count - 1; i++)
{
ddl.Items.Add(listcategory.Description);
}

Now that the control is in the gridview, ddl is not recognized.

I tried the following event but it does not seem to be reaching it.
protected void gridview_RowDataBound(object sender, DataGridItemEventArgs
e)
{
;
}
I also tried the template edit from the gridview properties but could not
see how to bind the dropdown box to the items listcategory.Description.
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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top