473,810 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ 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.Collect ions.ArrayList" .
Please help...

private void StoreCheckedIte ms()
{
ArrayList reasonIDList = new ArrayList();
int index = -1;
foreach (GridViewRow row in gvReason.Rows)
{
index = (int)gvReason.D ataKeys[row.RowIndex].Value;
bool result = ((CheckBox)row. FindControl("ch kReason")).Chec ked;
if (Session[CHECKED_ITEMS] != null)
reasonIDList = (ArrayList)Sess ion["CHECKED_IT EMS"];
if (result)
{
if (!reasonIDList. Contains(index) )
reasonIDList.Ad d(index);
}
else
reasonIDList.Re move(index);
}

Thanks!

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

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

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

--
Dave Sexton

"Sophie" <So****@discuss ions.microsoft. comwrote in message
news:57******** *************** ***********@mic rosoft.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.Collect ions.ArrayList" .
Please help...

private void StoreCheckedIte ms()
{
ArrayList reasonIDList = new ArrayList();
int index = -1;
foreach (GridViewRow row in gvReason.Rows)
{
index = (int)gvReason.D ataKeys[row.RowIndex].Value;
bool result = ((CheckBox)row. FindControl("ch kReason")).Chec ked;
if (Session[CHECKED_ITEMS] != null)
reasonIDList = (ArrayList)Sess ion["CHECKED_IT EMS"];
if (result)
{
if (!reasonIDList. Contains(index) )
reasonIDList.Ad d(index);
}
else
reasonIDList.Re move(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
2737
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 not the whole page, but a portion of the page. Strangely enough the URL below http://beta.asp.net/QUICKSTARTV20/aspnet/doc/ctrlref/data/gridview.aspx (VB GridView Paging and Sorting Callbacks example)
4
3861
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 another page and then back again, the value of the checkbox has been forgotten. Is there a better way of persisting the values through the pages in VS2005 other than writing tedious code behind in the OnPageIndexChanging event? Maybe using the...
1
4163
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 dgRegGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgRegGrid.PageIndexChanged I then do a loop to check the checkbox state.
2
5053
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 until it comes time to implement paging. Without paging I can iterate through the repeater when I click 'Select All' and set the checked property to true for all items in the repeater. However when I implement paging, I have to rebind the repeater...
1
3111
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) ( column 1 PK ) id : 1 2 3 4 5 6 (column 2 boolean) state : 1 , 0 , 1 , 0 , 1 , 0
8
18095
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 display data in a "GridView" which is tied to an "ObjectDataSource". In turn, this ObjectDatasource gets it's data from a strongly-typed business object within my code.
9
5539
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 another page)..i have been google around and found this.... If e.Row.RowType = DataControlRowType.DataRow Then Dim Chk As CheckBox = e.Row.FindControl("CheckBox1") just dont know what to do next...Any ideas?
2
13203
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 fields to be included in the table, which is to be bound to the gridview. The web form looks like so (Don't worry about the stupidity of this web form for now.):
2
4749
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 kind person would like me to email this link too I can do... My Grid View consists of 4 cols:- 1 - ItemTemplate (checkbox) 2 - imageField 3 - ItemTemplate (linkbutton) 4 - ImageField The data that Im binding too consist of nearly 1000...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10378
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10391
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.