After Paging how to hold checkboxvalues

11 posts, 0 answers
  1. BRK
    BRK avatar
    35 posts
    Member since:
    Jun 2012

    Posted 31 May 2011 Link to this post

    Hi Folks,

    I implemented  my business logic using RadGrid and Client Side Scripting. I also enabled Paging on RadGrid.
    If I check any checkboxes for pageindex=1 and then went for next records with pageindex=2 and while return back the checkbox values are
    missing they are showing empty.
    So Please Tell me how to hold those values for checkbox in RadGrid.
    looking for suggestions
    Thanking you all
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 31 May 2011 Link to this post

    Hi,

    method for clientSelectColumn

    <script type="text/javascript">
     var selected = {};
                function RadGrid1_RowSelected(sender, args) {
                    var StudentId = args.getDataKeyValue("StudentId");
                    if (!selected[StudentId]) {
                        selected[StudentId] = true;
                    }
                }
                function RadGrid1_RowDeselected(sender, args) {
                    var StudentId = args.getDataKeyValue("StudentId");
                    if (selected[StudentId]) {
                        selected[StudentId] = null;
                    }
                }
                function pageLoad(sender, args) {
                    var dataItems = $find('<%=RadGrid1.ClientID %>').get_masterTableView().get_dataItems();
                    for (var i = 0, j = dataItems.length; i < j; i++) {
                        var item = dataItems[i];
                        if (selected[item.getDataKeyValue("StudentId")]) {
                            item.set_selected(true);
                        }
                    }
                }
     </script>


    <telerik:RadGrid ID="RadGrid1" runat="server">
     <MasterTableView  ClientDataKeyNames="StudentId">
      
     <ClientSettings   Selecting-AllowRowSelect="true" EnableRowHoverStyle="true">
                            <ClientEvents OnRowSelected="RadGrid1_RowSelected" OnRowDeselected="RadGrid1_RowDeselected" />
                        </ClientSettings>
      
                    </telerik:RadGrid>


    method for asp:CheckBox

    http://www.telerik.com/help/aspnet/grid/gridpersistcheckboxstateingridtemplatecolumnonrebind.html

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. BRK
    BRK avatar
    35 posts
    Member since:
    Jun 2012

    Posted 31 May 2011 Link to this post

    Hi jayesh ,
    I cant Understand clearly. Please explain me and I implemented code but not showing results It is not holding any values
    If you have anyother solution please let me know
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 31 May 2011 Link to this post

    Hi brk,

    for selecting a row are you used "telerik:GridClientSelectColumn" or "asp:CheckBox" ??

    Thanks,
    Jayesh Goyani
  6. BRK
    BRK avatar
    35 posts
    Member since:
    Jun 2012

    Posted 31 May 2011 Link to this post

    I used asp:checkbox
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 31 May 2011 Link to this post

    Hello Brk,

    Take a look at the following demo demonstrates the same.
    Grid / Server-side Row Selection .

    Thanks,
    Shinu.
  8. BRK
    BRK avatar
    35 posts
    Member since:
    Jun 2012

    Posted 31 May 2011 Link to this post

    Hi People here my problem is whenever I check a checkbox that value must be hold even after I return to that after paging. Usually after paging from 1to 2 to 3 and coming back again 1 or 2 causes loss of checkbox value all checkbox values are getting cleared. I want a solution to hold those check values.

    If you have any solution suggest me
  9. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 31 May 2011 Link to this post

    Hi Brk,

    use below link for After Paging how to hold CheckBoxValue.

    http://www.telerik.com/help/aspnet/grid/gridpersistcheckboxstateingridtemplatecolumnonrebind.html

    By this method you can save checkboxvalue in viewstate and after changing the page index u can reassign their values.

    Thanks,
    Jayesh Goyani
  10. BRK
    BRK avatar
    35 posts
    Member since:
    Jun 2012

    Posted 31 May 2011 Link to this post

    That link is for OnCheckedChanged events. But here I am using Javascript clientside to fire checkbox event for that what I need to do
  11. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 31 May 2011 Link to this post

    Hi,

    1. take one hidden field.
    2. On checkBox click - get any primary key value
    3. than store/remove its (csv) value in hidden filed
    4. in ItemDataBound event if primary key value exists in hidden filed's value then set checkbox checked status.


    Thanks,
    Jayesh Goyani
  12. Adam
    Adam avatar
    5 posts
    Member since:
    May 2011

    Posted 22 Jun 2011 Link to this post

    here is my solution, seems to be working fine. I have been looking at this for a few days and was unable to find an answer....
    what I did, added prerender and onchecked methods to the checkbox, each checkbox's text is defined as a unique groupID which comes from my sqldatasource. server side, I have a bool[] with an arbitrary size(9999 for now), where each index refers to a group id. when a box is checked or unchecked the eventfires, I look to see if the incoming box is checked, if it is, i set the value at bool[int32.parse(checkbox.text)] to true, if not I set it false. then store bool[] in as a session variable.

    then when you change the page, it fires prerender on the checkboxes that will be rendered on the page. I simply grab the session variable. look at the index equal to  the text of the checkbox firing the event, if its true, set checked to true and bam.  

    asp.net:

    <radgrid1 ...>
    ...
    <MasterTableView TableLayout="Fixed">
    ...
    <asp:Panel
    <asp:CheckBox ID="cbChecked" Text='<%# Eval("GroupID") %>'  AutoPostBack="true" runat="server" CssClass="checkB" OnCheckedChanged="CheckChanged" OnPreRender="chkd" />

    ...........................................................

    .cs:
     bool[] checkbs;
            
            protected void CheckChanged(Object sender, System.EventArgs e)
            {     
                if (Session["checkbs"] == null)
                {
                     checkbs = new bool[9999];
                }
                else
                {
                    checkbs = (bool[])Session["checkbs"];
                }

                CheckBox box = (CheckBox)sender;
             
                if (box.Checked)
                {
                    checkbs[Int32.Parse(box.Text)] = true;
                }
                    
                else
                {
                    checkbs[Int32.Parse(box.Text)] = false;
                }
                Session["checkbs"] = checkbs;
            }



     protected void chkd(object sender, EventArgs e)
            {
                CheckBox a = sender as CheckBox;
                if (Session["checkbs"] != null)
                {
                    checkbs = (bool[])Session["checkbs"];
                    if (checkbs[Int32.Parse(a.Text)] == true)
                    {
                        a.Checked = true;
                    }
                }
                
            }



    hope this is helpful, does anyone see any flaws to this approach?
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017