How to keep the previous selection of the check box after performing search on preferred column in a RadGrid

2 posts, 1 answers
  1. Soumen
    Soumen avatar
    7 posts
    Member since:
    Jun 2020

    Posted 15 Jun 2020 Link to this post

    Hello,

    I am new in telerik radgrid, working in c#. I am working in a radgrid which have AllowFilteringByColumn feature. I am binding this grid from code behind every time. This grid have 2 extra CheckBox column. Problem is when I am performing any search page load is called and  the checked check box disappears after page load. How can I Resolve this problem. I need to keep the previous selection of the check box after performing search on preferred column.

     

    <telerik:RadGrid ID="grdAgreement" runat="server" SelectedItemStyle-CssClass="SelectedStyle"
                                        HeaderStyle-Height="40px" HeaderStyle-BackColor="#CEECF5" AutoGenerateColumns="False"
                                        GroupPanelPosition="Top" ResolvedRenderMode="Classic" Skin="Simple" Width="100%"
                                        ShowStatusBar="True" AllowMultiRowSelection="True" AllowFilteringByColumn="true"
                                        HeaderStyle-Font-Size="18px" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Arial Regular">
                                        <MasterTableView DataKeyNames="Id" >
                                            <Columns>                                            
                                                <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column"
                                                    HeaderText="ID" ReadOnly="True" SortExpression="Id" UniqueName="Id" Visible="true" AllowFiltering="false">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="DocumentTitle" FilterControlAltText="Filter DocumentTitle column"
                                                    HeaderText="Document Title" SortExpression="DocumentTitle" UniqueName="DocumentTitle" AllowFiltering="true"
                                                    AndCurrentFilterFunction="Contains" AutoPostBackOnFilter="True" AllowSorting="True"
                                                    HeaderStyle-Font-Size="18px" FilterControlWidth="120px">
                                                    <HeaderStyle Width="200px" HorizontalAlign="Center" />
                                                </telerik:GridBoundColumn>                                           
                                                <telerik:GridTemplateColumn HeaderText="Select for Template" AllowFiltering="false">
                                                     <ItemTemplate>
                                                              <asp:CheckBox ID="chkSelectForTemplate" Checked='<%# Eval("SelectforTemp") %>' runat="server" />
                                                     </ItemTemplate>
                                                </telerik:GridTemplateColumn> 
                                            </Columns>
                                        </MasterTableView>
                                        <HeaderStyle BackColor="#CEECF5" Height="40px"></HeaderStyle>
                                        <SelectedItemStyle CssClass="SelectedStyle"></SelectedItemStyle>
                                    </telerik:RadGrid>

     

    code behind

    if (!IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                {
                    string str_id = Request.QueryString["ID"].ToString();
                    if (str_id != "")
                    {
                        // code for select by ID
                        BindingGrid(str_id);
                    }
                }
                else
                {
                    BindingGrid();
                }           
            }
            else
            {            
            }

  2. Answer
    Attila Antal
    Admin
    Attila Antal avatar
    591 posts

    Posted 17 Jun 2020 Link to this post

    Hi Soumen,

    RadGrid is an extended version of the ASP GridView and it has its own binding technique. That is the Programmatic Data Binding Using the NeedDataSource Event.

    I recommend changing the binding technique for the Grid and test the application again. Once you bind the Grid using this technique, make sure the DataBind() method is not called anywhere in the code behind, see How to bind RadGrid properly on server-side

    Kind regards,
    Attila Antal
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top