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

Get Client Side Checkbox Values in Code Behind

8 Answers 399 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 27 Jun 2008, 07:30 PM
I am using the following in the RadGrid nested withing the MasterTable and Columns tags.

<telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" /> 

I also have a button above my grid to submit the form/grid to the code behind and update the checked rows.  Right now I am unable to access the checked rows.

How do I get the values of the checked rows in the code behind using an asp:Button? 

<asp:Button ID="ButtonAssignUsers" CssClass="emabtn"  OnClick="ButtonAssign_Click" CausesValidation="false" Width="225px" Text="Assign Users &raquo;" 
                                         runat="server" /> 

protected void ButtonAssign_Click(object sender, EventArgs e)  
  {      
    // What goes here so I can access the checked checkbox values?  
  } 

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Jun 2008, 06:33 AM
Hello Mike,

Check out the following code snippet to access the selected items in the grid.

CS:
protected void ButtonAssign_Click(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.SelectedItems) 
        { 
            string strtxt = item["ColumnUniqueName"].Text; 
        } 
    } 

Regards
Shinu.
0
Mike
Top achievements
Rank 1
answered on 30 Jun 2008, 12:39 PM

When I put that code it I get "&nbsp:" as a  value?  Here is a snippet of the updated code, what is wrong here?

a  value? 

<MasterTableView DataKeyNames="ID" AllowMultiColumnSorting="True" Width="99%">  
  <Columns> 
         <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" /> 
    
  </Columns>               
</MasterTableView> 
 
 
Code Behind  
protected void ButtonAssign_Click(object sender, EventArgs e)  
    {  
        foreach (GridDataItem item in RadGrid1.SelectedItems)  
        {  
            string strtxt = item["ClientSelectColumn"].Text;  
        }       
    }    

 

0
Princy
Top achievements
Rank 2
answered on 02 Jul 2008, 12:15 PM
Hi Mike,

You can access the CheckBox in the GridClientSelectColumn on clicking a button as shown below.

CS:
protected void ButtonAssign_Click(object sender, EventArgs e)     
    {     
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)  
        {  
            CheckBox chkbx = (CheckBox)item["ClientSelectColumn"].Controls[0];  
            if (chkbx.Checked)  
            {   
              
            }  
        }         
    }  


Thanks
Princy.
0
Mike
Top achievements
Rank 1
answered on 02 Jul 2008, 12:31 PM
What would go inside the brackets to get the value of the checkboxed item?
0
Princy
Top achievements
Rank 2
answered on 03 Jul 2008, 07:00 AM
Hi Mike,

Here is the code snippet I tried to access the cell text in a selected row on clicking a Button.

ASPX:
<Column> 
     <telerik:GridBoundColumn DataField="FirstName"  HeaderText="FirstName" ReadOnly="True" UniqueName="FirstName">  
        </telerik:GridBoundColumn> 
    <telerik:GridClientSelectColumn HeaderText="SelectCol" UniqueName="SelectCol" ></telerik:GridClientSelectColumn> 
  </Column> 

CS:
protected void Button1_Click(object sender, EventArgs e)  
    {  
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)  
        {  
            CheckBox chkbx = (CheckBox)item["SelectCol"].Controls[0];  
            if (chkbx.Checked)  
            {  
                  
                string strtxt = item["FirstName"].Text.ToString();  
            }  
        }  
    } 


Princy.
0
Mike
Top achievements
Rank 1
answered on 03 Jul 2008, 01:17 PM
I was hoping to get the DataKeys!

This will do the job for me, but if you can show how to get the DataKey that would be fantastic!

Thank you!
0
Accepted
Princy
Top achievements
Rank 2
answered on 05 Jul 2008, 06:32 AM
Hi Mike,

Here is the code snippet to access the DataKeyName on clicking the button.

CS:
 protected void Button1_Click(object sender, EventArgs e)  
    {  
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)  
        {  
            CheckBox chkbx = (CheckBox)item["SelectCol"].Controls[0];  
            if (chkbx.Checked)  
            {  
 
                string strKey = item.GetDataKeyValue("ProductName").ToString();  
            }  
        }    
    } 


Thanks
Princy.
0
Mike
Top achievements
Rank 1
answered on 13 Sep 2008, 06:41 PM
Thank you Princy!
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or