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

findcontrol returning null value for checkbox

1 Answer 283 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kranthi
Top achievements
Rank 1
Kranthi asked on 10 Jul 2012, 11:09 AM
HI All

i need to get only the values of the rows for which checkbox is checked, i am getting null values for the checkbox checked value pls help me out


i have a radgrid with asp checkbox column in gridtemplate column

this is my code aspx page for radgrid

            <telerik:RadGrid ID="M" runat="server" Width="99%" AllowPaging="True" EnableViewState="False"
                GridLines="None" meta:resourcekey="MResource1" AllowFilteringByColumn="true" 
                OnInit="GridControl_Init" EnableLinqExpressions="false" 
                EnableEmbeddedSkins="false" AutoGenerateColumns="false">
                <HeaderContextMenu EnableEmbeddedSkins="True">
                </HeaderContextMenu>
                <FilterMenu Skin="Nediso" EnableEmbeddedSkins="false">
                </FilterMenu>
                <PagerStyle Mode="NextPrevAndNumeric" Position="TopAndBottom" AlwaysVisible="true" />
                <MasterTableView Width="100%" EnableViewState="False" AllowFilteringByColumn="true" DataKeyNames="TOKEN" EditMode="EditForms">
                   <Columns>  
                            
                   <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" AllowFiltering="false" ForceExtractValue="Always" >
                  
                            <HeaderTemplate>
                             <asp:CheckBox id="Headercheck"  runat="server" onclick="SelectAll(this);"></asp:CheckBox>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox id="Childcheck" runat="server"  ></asp:CheckBox>
                            </ItemTemplate>
                             <HeaderStyle Width="3%" HorizontalAlign="Justify" />
                    <ItemStyle Width="3%" HorizontalAlign="Justify" />
                        </telerik:GridTemplateColumn>
                   <telerik:GridBoundColumn DataField="TOKEN" Visible="false" UniqueName="TOKEN" ReadOnly="true" >
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="FIRST NAME" HeaderText="FIRST NAME" UniqueName="FIRST NAME">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="LAST NAME" HeaderText="LAST NAME" UniqueName="LAST NAME">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="STATUS" HeaderText="STATUS" UniqueName="STATUS">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DESIGNATION" HeaderText="DESIGNATION" UniqueName="DESIGNATION">
                    </telerik:GridBoundColumn>
                     
                    </Columns>
                    <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" Position="TopAndBottom" />
                                 
                </MasterTableView>
                
                <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" EnableRowHoverStyle="True" EnablePostBackOnRowClick="true">
                    <Resizing AllowColumnResize="True" />
                    <Selecting AllowRowSelect="True"   />                    
                    <ClientEvents OnFilterMenuShowing="OnFilterMenuShowing"  ></ClientEvents> 
                    </ClientSettings>
                <FilterMenu EnableTheming="True">
                    <CollapseAnimation Type="None" />
                    <ExpandAnimation Type="None" />
                </FilterMenu>
                
            </telerik:RadGrid>

i have a button outside the radgrid, when i click the button it should get only the values checked in checkbox of radgrid 

this is my code for button click event

 protected void PushNtnBtn_Click1(object sender, EventArgs e)
        {




             foreach (GridDataItem item in M.MasterTableView.Items)
                {
                    //  bool isChecked = ((CheckBox)M.MasterTableView.FindControl("CheckBox1")).Checked;


                    CheckBox CheckBox1 = (CheckBox)item["CheckBoxTemplateColumn"].FindControl("Childcheck");


                    CheckBox c1 = item.FindControl("Childcheck") as CheckBox;
                    if (c1.Checked)
                    {
                        string token = item.GetDataKeyValue("TOKEN").ToString();
                        iPhnMainMethod(token);
                    }
                }
             }


      here both checkbox1 and c1 are returning null values, pls help me out

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Jul 2012, 11:44 AM
Hello,

Here is the sample code that I tried in an external button click event which worked as expected.
C#:
protected void Button1_Click(object sender, EventArgs e)
{
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            CheckBox chk = (CheckBox)item.FindControl("Childcheck");
            if (chk.Checked)
            {
                string token = item.GetDataKeyValue("TOKEN").ToString();
            }
        }
}

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