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

Get list of selected items inside a CheckBoxList in a FormTemplate

1 Answer 318 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Danielle Mascher
Top achievements
Rank 1
Danielle Mascher asked on 19 May 2010, 11:49 AM
Hi there

I'm struggling to find a way to get a list of all the selected items inside a CheckBoxList nested inside a grid's FormTemplate in the grid's Updatecommand.

I manage to get the values of all the other controls by using the following code:

String companyNameKey = Page.Request.Form.AllKeys.First(key => key.Contains("TextBoxCompanyName"));
String CompanyName = Page.Request.Form[companyNameKey];

But this does not seem possible for a CheckBoxList.

How should I do this?

Danielle





1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 May 2010, 02:06 PM
Hello Danielle,

In order to get all selected items of CheckBoxList, access the CheckBoxList using FindControl() method and then iterate through each listitems collection. Here is a sample code.

C#:
 protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    { 
        GridEditFormItem dataitem2 = (GridEditFormItem)e.Item; 
        CheckBoxList chklist = (CheckBoxList)dataitem2.FindControl("CheckBoxList1"); 
        foreach(ListItem item in chklist.Items) 
        { 
            if (item.Selected) 
            { 
                Response.Write(item.Text);//your code 
            } 
        } 
  } 

Regards,
Princy.
Tags
Grid
Asked by
Danielle Mascher
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or