473,321 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

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

myDataAdapter = new SqlDataAdapter(sqlQuery, myConnect);
myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet);
GvwCustomers.DataSource = myDataSet;
GvwCustomers.DataBind();
}
private void FindSelections()
{
foreach (GridViewRow row in GvwCustomers.Rows)
{
string customerID = GvwCustomers.DataKeys[row.RowIndex].Value.ToString();

CheckBox cbx = (CheckBox)row.FindControl("CbxSelected");

if (cbx.Checked)
Trace.Warn(customerID + " is selected");
else
Trace.Warn(customerID + " is NOT selected");
}
}
protected void GvwCustomers_PageIndexChanging(object sender,
GridViewPageEventArgs 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="GvwCustomers" runat="server" DataKeyNames="CustomerID"
AllowPaging="true"
AutoGenerateColumns="False"
OnPageIndexChanging="GvwCustomers_PageIndexChangin g">
<Columns>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:CheckBox ID="CbxSelected" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="ID" DataField="CustomerID" />
<asp:BoundField HeaderText="Name" DataField="ContactName" />
<asp:BoundField HeaderText="Title" DataField="ContactTitle" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
//***********************************************
Feb 23 '07 #1
0 4179

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...
2
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...
0
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...
1
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...
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...
0
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...
3
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...
2
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.