FindControl returns null for a checkbox inside a RadGrid

0 Answers 141 Views
General Discussions Grid
George
Top achievements
Rank 1
George asked on 14 Jul 2023, 06:34 AM | edited on 17 Jul 2023, 09:02 AM

Hello.

I need to check on each row of the grid if its checkbox is checked or not.

<tel:GridTemplateColumn HeaderStyle-Width="15px" UniqueName="gridTemplateColumnCheckbox">
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkItem" runat="server" AutoPostBack="false" CssClass="checkbox-item" />
                                    </ItemTemplate>
                                    <HeaderTemplate>
                                        <asp:CheckBox ID="chkSelectAll" runat="server" AutoPostBack="false" CssClass="checkbox-item-header" onclick="toggleCheckAll();" />
                                    </HeaderTemplate>
                                </tel:GridTemplateColumn>
Doncho
Telerik team
commented on 18 Jul 2023, 03:46 PM

Hi George,

You can check out how to access Controls inside RadGrid and specifically in Template Columns in the following article:

To be able to assist you more accurately I would ask you to share the complete markup declaration of the RadGrid along with all the relevant code-behind logic. That way I will be able to better understand the scenario and advise you accordingly.

Neha
Top achievements
Rank 2
Iron
Iron
commented on 21 Jul 2023, 12:04 PM | edited

Here's an example of how you can access the CheckBox control inside the ItemTemplate of the GridTemplateColumn


protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem dataItem)
    {
        CheckBox chkItem = dataItem.FindControl("chkItem") as CheckBox;

        if (chkItem != null)
        {
            // Access or modify the CheckBox control here
            bool isChecked = chkItem.Checked;
        }
    }
}

You have the OnItemDataBound event handler wired up to the RadGrid. You can do this in the markup.

 

<telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound">
    <!-- Your RadGrid configuration -->
</telerik:RadGrid>

I hope it helps. For more information see the Doc Official Doc


No answers yet. Maybe you can help?

Tags
General Discussions Grid
Asked by
George
Top achievements
Rank 1
Share this question
or