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

Read RadGrid CheckBox if checked or not and other values from RadGrid

3 Answers 532 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mmm
Top achievements
Rank 1
Mmm asked on 29 Mar 2011, 01:51 PM
ok I have RadGrid implemented, it works great and I can see my data
I implemented a checkbox control on that grid

<telerik:GridTemplateColumn HeaderText="Select"  UniqueName="AssetId">
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox1" runat="server" />
    </ItemTemplate>
</telerik:GridTemplateColumn>


Now I have a button on the page, under its click event I want to read all the rows which are checked
I am doing something similar but its not working.
I am unable to check the checkbox is checked or not.

   protected void UpdateButton_Click(object sender, EventArgs e)
    {
    for (int i = 0; i < RadGrid1.MasterTableView.Items.Count; i++)
            {
                bool isChecked = ((CheckBox)RadGrid1.MasterTableView.FindControl("CheckBox1")).Checked;
 
                if (isChecked)
                {
                    Label lbl = ((Label)RadGrid1.FindControl("lblRadItemId")) as Label;
                    LabelValue = ((Label)RadGrid1.Rows[i].Cells[8].FindControl("lblRadItemId")).Text;
                }
 
}




3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Mar 2011, 02:42 PM
Hello,
I have changed the code like below.
C#:
protected void Button2_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < rad.MasterTableView.Items.Count; i++)
        {
            bool isChecked = ((CheckBox)rad.MasterTableView.Items[i].FindControl("CheckBox1")).Checked;
        }
    }

Thanks,
Shinu.
0
Mmm
Top achievements
Rank 1
answered on 29 Mar 2011, 03:25 PM
Hi Shinu

Thanks for your reply, it works great, the only question I have now that when I check the checkbox the row is not highlighted

How can I highlight the row when checkbox is checked ??

and also when I click on a row it doesn't check the checkbox automatically ?

Please help

Thanks,

Moe
0
Shinu
Top achievements
Rank 2
answered on 30 Mar 2011, 06:51 AM
Hello,

For your first query, check out the following help article which explains how to achieve the same.
Selecting a row with a checkbox (server-side)

And for your second requirement, attatch the clent events OnRowDeselecting, OnRowSelecting and try the following code.
aspx:
<ClientSettings ClientEvents-OnRowSelecting="OnRowSelecting"  ClientEvents-OnRowDeselecting="OnRowDeselecting">
   <Selecting AllowRowSelect="true" />
</ClientSettings>

Javascript:
function OnRowSelecting(sender, args)
    {
        args.get_gridDataItem().findElement("CheckBox1").checked = true;
    }
    function OnRowDeselecting(sender, args)
    {
        args.get_gridDataItem().findElement("CheckBox1").checked = false;
    }

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