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

Cannot find Checkboxlist in RadGrid1_ItemUpdated

2 Answers 88 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Marco Rosignoli
Top achievements
Rank 1
Marco Rosignoli asked on 12 Apr 2010, 08:42 AM
I add by code my checkboxlist in ItemDataBound event
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
{  
 CheckBoxList chkLst = null;

// add checkboxlist only in edit item
 if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))  
 {  
      chkLst = new CheckBoxList();  
      chkLst.ID = "MyCheckLst";  
      lst = new ListItem("Item1""1");  
      chkLst.Items.Add(lst);  
      lst = new ListItem("Item2""2");  
      chkLst.Items.Add(lst);  
      // Add checkboxlist to CheckBox (every checkbox have a checkboxlist)

      (GridEditableItem)e.Item["MyCheck"

].Controls.Add(chkLst);

 

 }  
 
 
In RadGrid1_ItemUpdated event i try to retrive the checkboxlist
protected void RadGrid1_ItemUpdated(object source,Telerik.Web.UI.GridUpdatedEventArgs e)  
{  
    CheckBoxList cbl = (CheckBoxList)e.Item["MyCheckLst"].Controls[0];  
This is the error: 
{"Cannot find a cell bound to column name 'MyCheckLst'"} System.Exception {Telerik.Web.UI.GridException}

If I edit the row I can see the checkboxlist, but if I show page HTML I have not any checkboxlist!!!
Please, HELP!!!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Apr 2010, 11:38 AM

Hello Marco,

Try adding the CheckBoxList control in ItemCreated event also and check whether it is working fine.

CS:

 
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
        {  
            GridEditFormItem edititem = (GridEditFormItem)e.Item;  
            CheckBoxList chkLst;  
            ListItem lst;  
            chkLst = new CheckBoxList();  
            lst = new ListItem("Item1""1");  
            chkLst.Items.Add(lst);  
            lst = new ListItem("Item2""2");  
            chkLst.Items.Add(lst);  
            edititem["ColumnUniqueName"].Controls.Add(chkLst);  
        }  
    }  
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
        {  
            GridEditFormItem edititem = (GridEditFormItem)e.Item;  
            CheckBoxList chkLst;  
            ListItem lst;  
            chkLst = new CheckBoxList();  
            chkLst.ID = "MyCheckLst";  
            lst = new ListItem("Item1""1");  
            chkLst.Items.Add(lst);  
            lst = new ListItem("Item2""2");  
            chkLst.Items.Add(lst);  
            edititem["ColumnUniqueName"].Controls.Add(chkLst);  
        }  
    }  
 
    protected void RadGrid1_ItemUpdated(object source, GridUpdatedEventArgs e)  
    {  
        // Code for accessing the control  
        CheckBoxList cbl = (CheckBoxList)e.Item.FindControl("MyCheckLst");  
    }  

Also checkout the following link:

Distinguishing the major differences between ItemCreated and ItemDataBound events

-Shinu.

0
Marco Rosignoli
Top achievements
Rank 1
answered on 12 Apr 2010, 12:08 PM
GREAT!!!! Thanks so much!

 

 

 

Tags
General Discussions
Asked by
Marco Rosignoli
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Marco Rosignoli
Top achievements
Rank 1
Share this question
or