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

Get all checked values from GridClientSelectColumn

3 Answers 1086 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 14 Mar 2012, 12:32 PM
Hi everybody, as my title says, i have a GridClientSelectColumn, on my radGrid, and a button outside this grid, in this button, i try to get all checked check box on this way:
protected void btnDel_Click(object sender, EventArgs e)
{
    string id;
    bool chec;
    foreach (GridDataItem item in RadGrid2.Items)
    {
        CheckBox chk = (CheckBox)item["CheckboxColumn"].Controls[0];
        id = item["codigo"].Text;
        chec= chk.Checked;
    }
}

but if i try this way, i will get one by one valuee from checkbox that are checked.
Exist some way to get ALL rows that my gridClient are selected?
Thankz in advance

<telerik:RadGrid ID="RadGrid2" runat="server" AllowMultiRowSelection="true" Width="300px"
              OnNeedDataSource="RadGrid2_NeedDataSource">
              <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Novo Registro"
                  CommandItemSettings-RefreshText="Atualizar" DataKeyNames="codigo">
                  <Columns>
                      <telerik:GridClientSelectColumn UniqueName="CheckboxColumn" />
                      <telerik:GridBoundColumn HeaderText="Código" DataField="codigo" UniqueName="codigo" />
                      <telerik:GridBoundColumn HeaderText="Descrição" DataField="descricao" UniqueName="descricao" />
                  </Columns>
              </MasterTableView>
              <ClientSettings EnablePostBackOnRowClick="True">
                  <Selecting AllowRowSelect="true" />
              </ClientSettings>
          </telerik:RadGrid>
      <asp:Button ID="btnDeletar" CommandName="Delete" runat="server"
          Text="Deletar Items" onclick="btnDeletar_Click" />

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 14 Mar 2012, 01:11 PM
Hello,

I guess you want to loop through all selected rows.Check the following code.
C#:
foreach (GridDataItem item in RadGrid2.SelectedItems)
{
    //your code
}

Thanks,
Princy.
Had
Top achievements
Rank 1
Iron
commented on 15 May 2024, 12:59 AM

I try to loop all selected item like this but its only download/print for the first item only. Could anyone help to advise?

notes: optListCCl is a radio button list.

foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                CheckBox chk = (CheckBox)item["ClientSelectColumn"].Controls[0];
                
                SelectedItemLbl = item["FILENAME"].Text;
                cclID = item.GetDataKeyValue("ID").ToString();
                deliveryId = item["DELIVERY_ID"].Text;

                string filepath = SelectedItemLbl;
                chec = chk.Checked;

                if (optListCCl.SelectedItem.Value == "1")
                {
                    //Print Only
                    PrintOutContent();
                }
                else if(optListCCl.SelectedItem.Value == "2")
                {
                    //Download Only
                    downloadFile(SelectedItemLbl);
                }
            }


Vasko
Telerik team
commented on 16 May 2024, 09:22 AM

Hi Had,

The shared code appears to loop through all checked instances of the Grid rows, can you please check both functions being called and see if something in them breaks the loop?

Additionally, the following forum threads related to your question may help you out:

I hope this helps.

Regards,
Vasko
Progress Telerik

0
Bruno
Top achievements
Rank 1
answered on 14 Mar 2012, 01:29 PM
It works for me, thankz!
0
yook
Top achievements
Rank 1
answered on 14 Mar 2017, 04:26 AM

Hi,

I have a rad grid with paging enabled.I select all rows in multiple pages using a GridClientSelectColumn. When I click on print button it prints only the records which are displayed in first page,not all records selected in multiple pages. How to fix it. Plz help...

 

This is how i selected all checkboxes in multiple pages.

 var selected = {};
                function radGridWarehouseUtility_RowSelected(sender, args) {
                    var LID = args.getDataKeyValue("LID");
                    if (!selected[LID]) {
                        selected[LID] = true;
                    }
                }

                function radGridWarehouseUtility_RowDeselected(sender, args) {
                    var LID = args.getDataKeyValue("LID");
                    if (selected[LID]) {
                        selected[LID] = null;
                    }
                }

               function pageLoad() {
                   var dataItems = $find('<%=radGridWarehouseUtility.ClientID %>').get_masterTableView().get_dataItems();
                   for (var i = 0, j = dataItems.length; i < j; i++) {
                       var item = dataItems[i];
                       if (selected[item.getDataKeyValue("LID")]) {
                           item.set_selected(true);
                       }
                   }
               }

 

                        <ClientSettings EnablePostBackOnRowClick="true">
                            <Selecting AllowRowSelect="True"></Selecting>
                            <ClientEvents OnRowSelected="radGridWarehouseUtility_RowSelected"
                                OnRowDeselected="radGridWarehouseUtility_RowDeselected" />
                        </ClientSettings>

 

<telerik:GridClientSelectColumn UniqueName="Select" />

 

code behind...

 

Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPrint.Click

 For Each item As GridDataItem In radGridWarehouseUtility.SelectedItems
            Dim item1 As GridDataItem = item
            Dim chkBox As CheckBox
            chkBox = DirectCast(item1.Item("Select").Controls(0), CheckBox)

            If chkBox.Enabled Then
                Dim lid As String
                lid = CType(radGridWarehouseUtility.MasterTableView.DataKeyValues(item.ItemIndex)("LID"), String)
                qryParams = qryParams & lid & ","
            End If
        Next

End Sub

 

Thanks

Tags
Grid
Asked by
Bruno
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bruno
Top achievements
Rank 1
yook
Top achievements
Rank 1
Share this question
or