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

8 posts, 1 answers
  1. PPRINC
    PPRINC avatar
    9 posts
    Member since:
    Jun 2013

    Posted 18 Jun 2013 Link to this post

    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
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Jun 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. PPRINC
    PPRINC avatar
    9 posts
    Member since:
    Jun 2013

    Posted 19 Jun 2013 Link to this post

    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.
  5. PPRINC
    PPRINC avatar
    9 posts
    Member since:
    Jun 2013

    Posted 19 Jun 2013 Link to this post

    Thanks for your support Princy.

    Best regards,
  6. Salim
    Salim avatar
    10 posts
    Member since:
    Apr 2012

    Posted 30 Dec 2015 Link to this post

    Your quote goes here

    Hi Princy, 

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

  7. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1798 posts

    Posted 01 Jan Link to this post

    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
  8. Salim
    Salim avatar
    10 posts
    Member since:
    Apr 2012

    Posted 18 Jan in reply to Konstantin Dikov Link to this post

    I'm already using the advanced data binding but it doesn't work.
  9. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1798 posts

    Posted 19 Jan Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017