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

Can't get selected items on server side in a Radgrid with checkbox

11 Answers 1141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
PPRINC
Top achievements
Rank 1
PPRINC asked on 18 Jun 2013, 06:21 PM
Hello Dears,

I am facing an issue.

After upgrading from telerik v2009  to  telerk v2012 , I can't get my selected rows values in a radgrid with checkboxes from code behind

here is the code in the markup
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"
                          PageSize="5"     Width="100%"    OnPageIndexChanged="RadGrid1_PageIndexChanged"
                            GridLines="None" Skin="Vista" AllowMultiRowSelection="True"  >
                            <MasterTableView >
                            <Columns>
                                <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" ></telerik:GridClientSelectColumn>
                            </Columns>
                                <RowIndicatorColumn>
                                    <HeaderStyle Width="20px" />
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn>
                                    <HeaderStyle Width="20px" />
                                </ExpandCollapseColumn>
                                <PagerStyle Mode="NextPrev" />
                            </MasterTableView>
                            <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False"
                                Font-Strikeout="False" Font-Underline="False" Wrap="True" />
                            <ClientSettings EnableRowHoverStyle="true"  >
                                <Selecting AllowRowSelect="True" UseClientSelectColumnOnly "true"   />
                            </ClientSettings>
                        </telerik:RadGrid>
and now the code behind

 protected void  Ok_Click(object sender, System.EventArgs e)
        {
foreach (GridDataItem item in RadGrid1.SelectedItems)
               {
                   CheckBox chk = (CheckBox)item["ClientSelectColumn"].Controls[0];
                   id = item["ID"].Text; // get the id with its column name
                   name = item["NAME"].Text; // get the name with its column name
                   chec = chk.Checked;
 
 
               }
}

It doesn't even enter in the loop.
What can I do to resolve it ?

Thank in advance for your assistance

11 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Jun 2013, 12:14 PM
Hi,

I guess you want the selected row on a button click.Please try the code given below.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="True">
   <MasterTableView DataKeyNames="OrderID">
      <Columns>
          <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn"></telerik:GridClientSelectColumn>
     </Columns>
             <RowIndicatorColumn>
                   <HeaderStyle Width="20px" />
             </RowIndicatorColumn>
            <ExpandCollapseColumn>
                  <HeaderStyle Width="20px" />
             </ExpandCollapseColumn>
            <PagerStyle Mode="NextPrev" />
   </MasterTableView>
     <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
               Font-Underline="False" Wrap="True" />
    <ClientSettings EnableRowHoverStyle="true">
          <Selecting AllowRowSelect="True" UseClientSelectColumnOnly="true" />
    </ClientSettings>
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Ok" onclick="Button1_Click" />

C#:
protected void Button1_Click(object sender, EventArgs e)
{
  foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
   {
     CheckBox chk = (CheckBox)item["ClientSelectColumn"].Controls[0];
      if (chk.Checked)
       {
        string value = item["OrderID"].Text;// access the cell value using ColumnUniqueName
        Response.Write("<script language='javascript'>alert('" + value + " .');</script>");
       }
    }
}

Thanks,
Princy
0
PPRINC
Top achievements
Rank 1
answered on 19 Jun 2013, 01:18 PM
Aleardy found!

As i'm using master pages, I just needed to ad add a radAjaxManager on my master page and a radAjaxManagerProxy on the content page to get it fixed. and that's done.

Thanks anyway,

Regards.
0
PPRINC
Top achievements
Rank 1
answered on 19 Jun 2013, 01:25 PM
Thanks for your support Princy.

Best regards,
0
Salim
Top achievements
Rank 1
answered on 30 Dec 2015, 07:07 PM

[quote]Your quote goes here[/quote]

Hi Princy, 

I tried your code but the checkbox has always property .checked = False no matter what (even if I check it)

0
Konstantin Dikov
Telerik team
answered on 01 Jan 2016, 12:39 PM
Hi Salim,

The example will not work if you are using Simple Data-Binding and if you are calling the DataBind method on each postback. Please use the Advanced Data-Binding instead and see if the approach will work:

Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Salim
Top achievements
Rank 1
answered on 18 Jan 2016, 09:38 PM
I'm already using the advanced data binding but it doesn't work.
0
Konstantin Dikov
Telerik team
answered on 19 Jan 2016, 09:45 AM
Hello Salim,

Could you please open a regular support ticket and attach a sample page demonstrating the issue in question?

Meanwhile you can ensure that you are not disabling the ViewState of the controls and that you are not calling DataBind or Rebind methods, before you try to retrieve the CheckBox value.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Dave
Top achievements
Rank 1
answered on 12 Jan 2017, 01:40 PM

Salim, did you ever get a resolution on this?  Having the same problem.

-Dave

0
Dave
Top achievements
Rank 1
answered on 12 Jan 2017, 02:29 PM
Nevermind...if I place my databind in Page_PreRender instead of Page_Load it works.  I couldn't find any obvious solution to this...just trial and error.
0
yook
Top achievements
Rank 1
answered on 14 Mar 2017, 04:31 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
0
yook
Top achievements
Rank 1
answered on 14 Mar 2017, 04:31 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
PPRINC
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
PPRINC
Top achievements
Rank 1
Salim
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Dave
Top achievements
Rank 1
yook
Top achievements
Rank 1
Share this question
or