473,666 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Persist Checkboxes While Paging in Gridview

Hi,

I have a .NET page which has a gridview of customers from Northwind
database. There's a checkbox for each customer and the gridview allows
paging.

I would like to be able to persist the checkbox status while paging. I'm
starting with the code below but I can't get it to work. You can check some
of the checkboxes and when you click on the pager, no selection is reflected
by the trace. Why's that?
Thanks,
ywb
//*************** *************** *************** **
<%@ Page Language="C#" Trace="true" %>

<%@ Import Namespace="Syst em.Data" %>
<%@ Import Namespace="Syst em.Data.SqlClie nt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

protected SqlConnection myConnect;
protected SqlDataAdapter myDataAdapter;
protected SqlCommand myCommand;
protected DataSet myDataSet;
protected void Page_Load(objec t sender, EventArgs e)
{
myConnect = new
SqlConnection(" server=(local); database=Northw ind;uid=sa;pwd= ;");
BindData();
}
private void BindData()
{
string sqlQuery = "SELECT * FROM Customers";

myDataAdapter = new SqlDataAdapter( sqlQuery, myConnect);
myDataSet = new DataSet();
myDataAdapter.F ill(myDataSet);
GvwCustomers.Da taSource = myDataSet;
GvwCustomers.Da taBind();
}
private void FindSelections( )
{
foreach (GridViewRow row in GvwCustomers.Ro ws)
{
string customerID = GvwCustomers.Da taKeys[row.RowIndex].Value.ToString ();

CheckBox cbx = (CheckBox)row.F indControl("Cbx Selected");

if (cbx.Checked)
Trace.Warn(cust omerID + " is selected");
else
Trace.Warn(cust omerID + " is NOT selected");
}
}
protected void GvwCustomers_Pa geIndexChanging (object sender,
GridViewPageEve ntArgs e)
{
FindSelections( );
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Paging with Checkboxes</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GvwCustomer s" runat="server" DataKeyNames="C ustomerID"
AllowPaging="tr ue"
AutoGenerateCol umns="False"
OnPageIndexChan ging="GvwCustom ers_PageIndexCh anging">
<Columns>
<asp:TemplateFi eld HeaderText="Del ete">
<ItemTemplate >
<asp:CheckBox ID="CbxSelected " runat="server" />
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld HeaderText="ID" DataField="Cust omerID" />
<asp:BoundFie ld HeaderText="Nam e" DataField="Cont actName" />
<asp:BoundFie ld HeaderText="Tit le" DataField="Cont actTitle" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
//*************** *************** *************** **
Feb 23 '07 #1
0 4191

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

Similar topics

0
2727
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)
2
16335
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging feature will not work. When I try to use paging I get this error: The GridView 'gvResults' fired event PageIndexChanging which wasn't handled.
0
1263
by: Samy | last post by:
Hi There, I have a grid view which has paging enabled in it. One of the colums is a check box and checkbox selections shows a subset of rows a user has selected from available rows. I need to update the dataset by checking the rows selected by a user. What is the best way to do that? I have paging enabled in the gridview and if the user selects some rows in the first page and a few rows in the second page, I save the ids in the...
1
2941
by: davidjgonzalez | last post by:
I have a GridView that has paging enabled. Each item (as defined in an ItemTemplate) includes several controls which have operations i would like to Atlas-enable. Everything is working well except when I page the GridView (the paging controllers are in the gridview's footer). The webpage doesnt scroll back to the top of the page, so when paging through the GridView the user is always looking at the last 4-5 items on the page. My current...
2
13179
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.):
0
2001
by: Don Miller | last post by:
Here is an example of what I believe is a bug in ASP.NET 2.0 GridView paging without postbacks (or at least not documented how to fix it). Once the GridView is displayed, clicking on any of the paging tools causes the GridView to completely disappear! This happens when either DataSets or DataTables are used (it doesn't work at all for DataReaders because they don't support paging apparently). If you remove the...
3
3739
by: Ronald S. Cook | last post by:
I was told that if calling lots of records from the database (let's say 100,000), that the GridView's paging feature would automatically "handle" everything. But the 100,000 records are still coming to the client, right? I mean, the paging feature isn't somehow making calls to the database for 25 records at a time or anything like that is it? I remember in the past having to write nasty stored procedures that took in
2
2820
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
1
4509
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this checkbox is checked, all of the rows in the GridView are checked, if this checkbox is unchecked, all of the rows in the GridView are unchecked. This checking/unchecking of the checkboxes in the GridView is handled by a JavaScript method: function...
0
8871
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
8781
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
8551
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
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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
1776
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.