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

Accessing checkbox control

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
psiegers45
Top achievements
Rank 1
psiegers45 asked on 24 Oct 2013, 07:57 PM
Hi, I just updated our Telerik ASP.NET AJAX Radcontrols from Q3 2009 to Q3 2013, and the following code is not working anymore (see below), can somebody help me please?

The page has this declaration in the DetailView part of the RadGrid (inside columns):

                                    <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn2" DefaultInsertValue="">
                                        <ItemTemplate>
                                            <asp:Panel ID="Panel2" runat="server">
                                                <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("band") %>' OnCheckedChanged="checked_value" AutoPostBack="True"></asp:CheckBox>
                                            </asp:Panel>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>

This checkbox can be checked by the user and needs to be extracted to be able to gather selected rows in master/detail grid.
The code that used to work is:

                    foreach (GridDataItem gdi in RadGrid1.Items)
                    {
                        if (gdi.ItemType == GridItemType.Item ||
                            gdi.ItemType == GridItemType.AlternatingItem)
                        {
                            try
                            {
                                if (gdi["CheckBoxTemplateColumn2"] != null &&
                                    ((CheckBox)gdi["CheckBoxTemplateColumn2"].FindControl("CheckBox2")).Checked)
                                {
                                    if (gdi["deliveryNote"].Text.Trim() != "&nbsp;")
                                        deliveryNote += gdi["deliveryNote"].Text + ",";
                                    materialDocument += gdi["MaterialDocument"].Text + ",";
                                    purchaseOrder += gdi["purchaseOrder"].Text + ",";
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }

The exception is entered when C# tries to execute this: gdi["CheckBoxTemplateColumn2"] and in debug it is throwing exception too.

Any help would be much appreciated.

Regards, Pieter

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Oct 2013, 04:58 AM
Hi,

I guess you want to access the checkbox inside details view in its OnCheckedChanged event.Please try the following code snippet.

C#:
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
    try
    {
        CheckBox check = (CheckBox)sender;
        GridEditableItem edit = (GridEditableItem)check.NamingContainer;
        if (check.Checked)
        {
            //Your Code
        }
    }
    catch (Exception ex)
    {
    }
}

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