I am trying to get the checkbox multirow selection on radgrid but I am not able to get it. Need some help.

1 Answer 73 Views
AJAX and Web 2.0
Shweta
Top achievements
Rank 1
Shweta asked on 12 Aug 2021, 04:55 PM

This is my aspx file.

 <telerik:RadGrid RenderMode="Lightweight" runat="server" ID="RadGrid2"  
                ShowStatusBar="true" ClientSettings-Scrolling-AllowScroll="true" AllowPaging="True" AllowSorting="true"  
            OnNeedDataSource="RadGrid2_NeedDataSource"  AllowMultiRowSelection="true"  Width="1500px"  AllowFilteringByColumn="true" CssClass="RadGrid">  


         <MasterTableView PageSize="10">
                <Columns>
                    <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn">
                    </telerik:GridClientSelectColumn>
                </Columns>
            </MasterTableView>
         <ClientSettings  EnableRowHoverStyle="true">
              <Selecting AllowRowSelect="True"></Selecting>
                <ClientEvents OnRowMouseOver="demo.RowMouseOver" />
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true"></Scrolling>
              <Selecting AllowRowSelect="true" UseClientSelectColumnOnly="true" />
    <ClientEvents OnRowClick="toggleSelection" />
              <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                </ClientSettings>
                <HeaderStyle Width="225px"></HeaderStyle>

This is my .cs file

  protected void RadGrid1_PreRender(object sender, System.EventArgs e)
        {
            RadGrid2.Items[4].SelectableMode = GridItemSelectableMode.None;
            RadGrid2.Items[5].SelectableMode = GridItemSelectableMode.None;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridItem item in RadGrid2.MasterTableView.Items)
            {
                GridDataItem dataitem = (GridDataItem)item;
                TableCell cell = dataitem["ClientSelectColumn"];
                CheckBox checkBox = (CheckBox)cell.Controls[0];
                if (checkBox.Checked)
                {
                    string value = dataitem.GetDataKeyValue("SVC TAG").ToString();
                }
            }
        }                       

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 17 Aug 2021, 09:44 AM

Hi Shweta,

You will need to use the SelectedItems collection as well as the solution provided at Accessing Selected items from a Button Click, e.g.

protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridDataItem selectedItem in RadGrid2.SelectedItems)
    {
        string value = selectedItem.GetDataKeyValue("SVC TAG").ToString();
    }
}

RadGrid1.SelectedItems is of type GridItemsCollection, but it consists of  GridDataItem objects only so you can easily cast it to GridDataItem as shown in the code sample above.

Best Regards,
Rumen
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
AJAX and Web 2.0
Asked by
Shweta
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or