This is a migrated thread and some comments may be shown as answers.

[Solved] Binding a droplist in the edit template of a detail grid

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 29 Mar 2013, 07:43 PM
I have two grids on the page. Both are configured to use the OnNeedDataSource event. The detail grid is rebound in the OnSelectedIndexChange of the master grid.  The detail grid has an edit template with a dropdownlist.  The dropdown list is bound to an ObjectDataSource.  I'm attempting to bind the dropdownlist in the following event handler;

protected void ModelGrid_OnItemDataBound(object sender, GridItemEventArgs e)
{
   if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
   {
        GridEditFormItem editform = (GridEditFormItem)e.Item;
        DropDownList ddlAType = (DropDownList)editform.FindControl("ddlAssetType");
        if (ddlAType != null)
            ddlAType.DataBind();
   }
}

However, before it can get here, I get an error: "Sys.WebForms.PageRequestManagerServerErrorException: 'ddlAssetType' has a SelectedValue which is invalid because it does not exist in the list of items."

The code doesn't hit a breakpoint set in the OnSelect method of the ObjectDataSource, so the dropdownlist hasn't been bound yet. What am I doing wrong?


1 Answer, 1 is accepted

Sort by
0
Steven
Top achievements
Rank 1
answered on 30 Mar 2013, 12:46 AM
Was binding the wrong field. 
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Steven
Top achievements
Rank 1
Share this question
or