473,472 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to keep checkbox state in gridview while paging?

Is it possible to use session by cast it to an array to keep gridview primary
key?
I have the following code in place, but it gives me error saying "Unable to
cast object of type 'System.String' to type 'System.Collections.ArrayList".
Please help...

private void StoreCheckedItems()
{
ArrayList reasonIDList = new ArrayList();
int index = -1;
foreach (GridViewRow row in gvReason.Rows)
{
index = (int)gvReason.DataKeys[row.RowIndex].Value;
bool result = ((CheckBox)row.FindControl("chkReason")).Checked;
if (Session[CHECKED_ITEMS] != null)
reasonIDList = (ArrayList)Session["CHECKED_ITEMS"];
if (result)
{
if (!reasonIDList.Contains(index))
reasonIDList.Add(index);
}
else
reasonIDList.Remove(index);
}

Thanks!

Sophie
Dec 2 '06 #1
1 2526
Hi Sophie,

What does the code look like that assigns Session["CHECKED_ITEMS"]?

I assume that it's being assigned to a string, hence the error.

--
Dave Sexton

"Sophie" <So****@discussions.microsoft.comwrote in message
news:57**********************************@microsof t.com...
Is it possible to use session by cast it to an array to keep gridview
primary
key?
I have the following code in place, but it gives me error saying "Unable
to
cast object of type 'System.String' to type
'System.Collections.ArrayList".
Please help...

private void StoreCheckedItems()
{
ArrayList reasonIDList = new ArrayList();
int index = -1;
foreach (GridViewRow row in gvReason.Rows)
{
index = (int)gvReason.DataKeys[row.RowIndex].Value;
bool result = ((CheckBox)row.FindControl("chkReason")).Checked;
if (Session[CHECKED_ITEMS] != null)
reasonIDList = (ArrayList)Session["CHECKED_ITEMS"];
if (result)
{
if (!reasonIDList.Contains(index))
reasonIDList.Add(index);
}
else
reasonIDList.Remove(index);
}

Thanks!

Sophie

Dec 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
4
by: Paul Hale | last post by:
Hi, Currently using VS2005 c# Scenario: I have a gridview control displaying many items with paging enabled. Column is a checkbox column which users can check, but when the gridview is paged to...
1
by: iforsyth | last post by:
Have a paging datagrid with a checkbox control in column(0). ViewState is enabled. I check the checkbox in first row of the grid on a page and then the program hits this event: Private Sub...
2
by: Mark | last post by:
I am attempting to build a repeating list using a repeater control. I want to add a checkbox to each item (line) and 'Select All' and 'Clear All' buttons. I have figured out how to do this...
1
by: aspnoob | last post by:
hello i just started off with asp.net , needed some help on how to display the state of checkboxes from a SQL database. my database table has the following format seat.dbo ( db design) (...
8
by: Greg Lyles | last post by:
Hi all, I'm trying to develop an ASP.NET 2.0 website and am running into some real problems with what I thought would be a relatively simple thing to do. In a nutshell, I'm stuck on trying to...
9
by: mike7510uk | last post by:
Hi, I am using a gridview with a templatefield containing a checkbox. I want to update the database with a 1 or 0 depending on if a checkbox is checked or unchecked (then use the 1 or 0 later on...
2
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
2
by: dixonjm | last post by:
I have quite a complicated problem with the above. I will do my best to explain, although I have a word doc (too large to attach here 149KB) with the problem explained full with screen shots if any...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.