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

Can't find DropDownList in EditTemplate while Edit

2 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Or Huang
Top achievements
Rank 1
Or Huang asked on 01 Apr 2010, 06:31 AM
Hi All :

protected void radgrdList_EditCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        this.radgrdList.MasterTableView.Items[e.Item.ItemIndex].Edit = true;
        GridEditableItem item = (GridEditableItem)e.Item;
        Guid id = (Guid)item.GetDataKeyValue("CatalogID");
        ContentCatalog catalog = new ContentCatalog().GetOne(id);
        DropDownList ddlPosition = (DropDownList)item["position"].FindControl("ddlPosition");
        if (!String.IsNullOrEmpty(catalog.Position))
        {
            ddlPosition.Items.FindByValue(catalog.Position);
        }
        this.radgrdList.MasterTableView.Rebind();
    }

I cant't findcontrol "ddlPosition" and return null

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Apr 2010, 07:43 AM
Hi,

Since the EditCommand is too early to access the edit form items, you can access the items in the ItemDataBound event of the grid.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
{             
    GridEditableItem editItem = e.Item as GridEditableItem; 
    DropDownList ddlPosition = (DropDownList)editItem["position"].FindControl("ddlPosition");      
...    
}    

Regards
Princy
0
Or Huang
Top achievements
Rank 1
answered on 02 Apr 2010, 02:21 AM
Hi Princy

    Thank you

     I use your suggestion , then I can find the DropDownList

     Thank you again
Tags
Grid
Asked by
Or Huang
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Or Huang
Top achievements
Rank 1
Share this question
or