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

How to loop RadGrid (EditItemTemplate) in ItemCommand Event

3 Answers 180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aret
Top achievements
Rank 1
Aret asked on 23 Apr 2013, 12:55 PM
I have a checkboxlist in my RadGrid (EditItemTempalte) that gets bound with data in insert mode.  I need to be able to reference the ID of this control and loop through it to gather the selected values in the Item Command Event.  How would I go about this...?  Here is the example I am talking about:

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Apr 2013, 01:10 PM
Hi,

Try the following code.
C#:
protected void RadGrid5_ItemCommand(object sender, GridCommandEventArgs e)
{
        if (e.CommandName == "commandname")
        {
            foreach (GridEditableItem item in RadGrid5.EditItems)
            {
                CheckBox chk = (CheckBox)item.FindControl("CheckBox 1");
            }
        }
}

Thanks,
Princy
0
Aret
Top achievements
Rank 1
answered on 23 Apr 2013, 02:04 PM
That code works ONLY when the grid is in EDIT mode.  I need it to loop through the controls when it is in INSERT mode.
0
Princy
Top achievements
Rank 2
answered on 25 Apr 2013, 05:52 AM
Hi,

You can access the CheckBoxList in ItemCommand in insert mode as follows.

C#:
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {           
        e.Item.OwnerTableView.InsertItem();
        GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
        GridEditFormItem editFormItem = insertedItem as GridEditFormItem;
        CheckBoxList chkList = (CheckBoxList)editFormItem.FindControl("CheckBoxList1"); //access the CheckBoxList
             
    }

Thanks,
Princy.
Tags
Grid
Asked by
Aret
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Aret
Top achievements
Rank 1
Share this question
or