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

Getting Checked Value in RadGrid

3 Answers 90 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 01 Sep 2011, 09:17 PM
I am trying to get the Checked value of the check box, such as true or false in a RadGrid and for some reason it always says that the value is false.

This is my Grid:
<telerik:radgrid id="grdLeadList" runat="server" autogeneratecolumns="false" allowpaging="True"
     allowsorting="True" pagesize="5" allowautomaticupdates="true" gridlines="None"
     allowmultirowselection="true" onitemcommand="grdLeadList_ItemCommand" DataKeyNames="opportunityid" style="float: left; width: 965px;">
 <ExportSettings HideStructureColumns="true" >
     <Excel Format="ExcelML" />
     <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" />
     <Pdf />
 </ExportSettings>
 <PagerStyle Mode="NextPrevNumericAndAdvanced" />
 <MasterTableView Width="100%" TableLayout="Auto"  >
     <CommandItemSettings ShowExportToExcelButton="false" ShowExportToCsvButton="false" ShowExportToPdfButton="false" ShowAddNewRecordButton="false" />
     <Columns>
         <telerik:GridTemplateColumn UniqueName="CkhSelect" HeaderText="Select">
           <ItemTemplate>
             <asp:CheckBox ID="chkbxselect" runat="server" />
           </ItemTemplate>
         </telerik:GridTemplateColumn>
         <telerik:GridEditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit" />
         <telerik:GridBoundColumn DataField="CustomerId" HeaderText="Company Name" SortExpression="CompanyName" UniqueName="CompanyName" />
         <telerik:GridBoundColumn DataField="Priority" HeaderText="Priority" SortExpression="Priority" UniqueName="Priority" />
         <telerik:GridBoundColumn DataField="Eval" HeaderText="Eval" SortExpression="Eval" UniqueName="Eval" />
         <telerik:GridBoundColumn DataField="ContactName" HeaderText="Contact Name" SortExpression="ContactName" UniqueName="ContactName" />
         <telerik:GridBoundColumn DataField="Source" HeaderText="Source" SortExpression="Source" UniqueName="Source" />
         <telerik:GridBoundColumn DataField="State" HeaderText="State" SortExpression="State" UniqueName="State" />
         <telerik:GridNumericColumn DataField="Zip" HeaderText="Zip" SortExpression="Zip" UniqueName="Zip" />
         <telerik:GridDateTimeColumn DataField="CreatedOn" DataFormatString="{0:MM/dd/yy}" HeaderText="Creation Date" SortExpression="CreationDate" UniqueName="CreationDate" />
     </Columns>
     <EditFormSettings UserControlName="EditPanel.ascx" EditFormType="WebUserControl">
         <EditColumn UniqueName="EditCommandColumn1" />
     </EditFormSettings>
 </MasterTableView>
 <ClientSettings EnableRowHoverStyle="false" >
     <Selecting AllowRowSelect="True"  />
 </ClientSettings>
 </telerik:radgrid>


This my C#:
protected void imgBtnSendRecords_Click(object sender, ImageClickEventArgs e)
{
    string mail = "";
 
    foreach (GridDataItem item in grdLeadList.MasterTableView.Items) //loop through each grid item
    {
        CheckBox chkSelected = (CheckBox)item.FindControl("chkbxselect");
        if (chkSelected.Checked == true)
        {
            mail = mail + item["Priority"].Text + " ";
 
        }
    }
 
}


Any help would be great!

Thanks!

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Sep 2011, 05:57 AM
Hello Justin,

You can check for the condition as shown below which returns true on checking the CheckBox.
C#:
protected void imgBtnSendRecords_Click(object sender, ImageClickEventArgs e)
{
  if (chkSelected.Checked)
  {
     //some condition
  }
}

Thanks,
Princy.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Sep 2011, 06:00 AM
Hello,

There are many reasons for this type of issue.
One of reason is that before you fetch the selected item. May be your grid was bind the Data again so it will lost the selected items.
Please use below method for binding the data.
Grid / Advanced Data Binding

Thanks,
Jayesh Goyani
0
Justin
Top achievements
Rank 1
answered on 02 Sep 2011, 03:23 PM
Thanks for the reply!

I got it working by moving it to OnInit and it works good. The only problem is the checkboxes don't clear after the Send button is clicked. Anyway around that?

Thanks!
Tags
Grid
Asked by
Justin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Justin
Top achievements
Rank 1
Share this question
or