Click to See Complete Forum and Search --> : gridview dropdown list rowdatabound


jrieder
September 18th, 2007, 02:36 PM
Everyone says you customize the gridview in the rowdatabound event. I have been able to add footer totals, check boxes and dropdown lists in template, modified in rowdatabound. But,I have a weird problem with rowdatabound that I cannot seem to find any reference to...I must be doing something wrong....

I populate the gridview on page load...then update my columns rowdatabound. They populate as expected with one exception The dropdown list in the first row are empty. Stepping through code I also notice that I cannot set the Selected value for the first rowdatabound row ddl's it is in the cache but the ddl does not populate on the first item...maybe a postback then occurs because the dropdown list in rows 2 thru last are populated and have a selected value?

Just what is occurring here? I will gladly post code from my rowdatabound below...Thanks for any assistance.


if (e.Row.RowType == DataControlRowType.DataRow)
{
int ProjectId = Convert.ToInt32(Session["ProjectId"]);
// populate the dropdown list
_presenter.SetViewWorkCodeGridDropDown(ProjectId);
// get work code to use to select the dropdown list
workCodeId = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "WorkCodesId"));
DropDownList ddl = (DropDownList)e.Row.FindControl("WorkCodeDropDown");
ddl.SelectedValue = workCodeId.ToString();

Note: all first row data in the grid view is present and accurate with the exception of no items in my dropdown list ??