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

After Paging how to hold checkboxvalues

10 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BRK
Top achievements
Rank 1
BRK asked on 31 May 2011, 06:22 AM
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

10 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 31 May 2011, 06:32 AM
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
0
BRK
Top achievements
Rank 1
answered on 31 May 2011, 12:33 PM
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
0
Jayesh Goyani
Top achievements
Rank 2
answered on 31 May 2011, 12:57 PM
Hi brk,

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

Thanks,
Jayesh Goyani
0
BRK
Top achievements
Rank 1
answered on 31 May 2011, 01:05 PM
I used asp:checkbox
0
Shinu
Top achievements
Rank 2
answered on 31 May 2011, 01:19 PM
Hello Brk,

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

Thanks,
Shinu.
0
BRK
Top achievements
Rank 1
answered on 31 May 2011, 01:31 PM
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
0
Jayesh Goyani
Top achievements
Rank 2
answered on 31 May 2011, 01:32 PM
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
0
BRK
Top achievements
Rank 1
answered on 31 May 2011, 01:43 PM
That link is for OnCheckedChanged events. But here I am using Javascript clientside to fire checkbox event for that what I need to do
0
Jayesh Goyani
Top achievements
Rank 2
answered on 31 May 2011, 02:07 PM
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
0
Adam
Top achievements
Rank 1
answered on 22 Jun 2011, 09:32 PM
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?
Tags
Grid
Asked by
BRK
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
BRK
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Adam
Top achievements
Rank 1
Share this question
or