473,382 Members | 1,775 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,382 software developers and data experts.

Paging for gridview is not working.can any one help me

my .cs file is
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
DataTable dt;
DataTable DBView = new DataTable();

protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false )
{
dt = new DataTable("tblTest");
DataColumn dc1 = new DataColumn();
dc1.DataType = typeof(String);
dc1.ColumnName = "Name";
DataColumn dc2 = new DataColumn();
dc2.DataType = typeof(String);
dc2.ColumnName = "Add1";
DataColumn dc3 = new DataColumn();
dc3.DataType = typeof(String);
dc3.ColumnName = "Add2";

dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);

Session["Name"] = "Rupa" + "|";
Session["Add1"] = "3" + "|";
Session["Add2"] = "ffdfd" + "|";
CreateTable();
Session["Name"] = "Rupa2" + "|";
Session["Add1"] = "1" + "|";
Session["Add2"] = "ffdfd" + "|";
CreateTable();
Session["Name"] = "Rupa3" + "|";
Session["Add1"] = "4" + "|";
Session["Add2"] = "ffdfd" + "|";
CreateTable();
Session["Name"] = "Rupa4" + "|";
Session["Add1"] = "5" + "|";
Session["Add2"] = "ffdfd" + "|";
CreateTable();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int cnt = GridView1.Rows.Count;
for (int i = 0; i < cnt; i++)
if (((CheckBox)(GridView1.Rows[i].Cells[0].FindControl("CheckBox1"))).Checked == true)
GridView1.Rows[i].BackColor = System.Drawing.Color.AliceBlue;

}
public void CreateTable()
{

string[] sa = Session["Name"].ToString().Split('|');
string[] sb = Session["Add1"].ToString().Split('|');
string[] sc = Session["Add2"].ToString().Split('|');
int recordnum = sa.Length;

for (int j = 0; j < recordnum - 1; j++)
{

DataRow dr = dt.NewRow();
dr["Name"] = sa[j].ToString();
dr["Add1"] = sb[j].ToString();
dr["Add2"] = sc[j].ToString();
dt.Rows.Add(dr);

}

GridView1.DataSource = dt.DefaultView;
GridView1.DataBind();


}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{

DataView DBView;
DataTable Dbdatatable;
DBView = dt.DefaultView;
string sDirection;

if (ViewState["sortDirection"] == null)
{
ViewState["sortDirection"] = SortDirection.Ascending;
sDirection = " ASC";
}

else
{
ViewState["sortDirection"] = SortDirection.Descending;
sDirection = " DESC";
}


DBView.Sort = e.SortExpression;// +SortDirection.Ascending;
this.GridView1.DataSource = dt;
this.GridView1.DataBind();

}
protected void Button1_Click1(object sender, EventArgs e)
{
int rowCount = GridView1.Rows.Count;
for (int i=0;i<rowCount;i++)

{
if (((CheckBox)(GridView1.Rows[i].Cells[0].FindControl("CheckBox1"))).Checked == true)
GridView1.Rows[i].BackColor = System.Drawing.Color.PaleGreen;
}
}
}

my aspx file is
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<script type="text/javascript" src="wz_tooltip.js">
//function Button1_onclick()
//{
//document[0].write("HAi");
//}

</script>


<form id="form1" runat="server">
<a href="Default.aspx" onmouseover="Tip('Some text')">Homepage </a>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="2" OnSorting="GridView1_Sorting">
<Columns>
<asp:CheckBoxField />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SE Name">
<ItemTemplate>
<a href="<%# String.Format("~/Default2.aspx?Name={0}", Eval("Name")) %>" onmouseover="Tip('<%# Eval("Name")%>')" onmouseout="hide('<%# Eval("Name") %>')"><%# Eval("Add1")%>'</a>
<%--<div style="display:none;" id='<%# Eval("Name") %>'><%# Eval("Name")%></div>--%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div>
&nbsp;<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" /></div>
</form>
</body>
</html>
Nov 6 '07 #1
4 3490
kunal pawar
297 100+
try this one

session["dtSess"]=dt.DefaultView
GridView1.DataSource = dt.DefaultView;
GridView1.DataBind();


}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = (DataTable) session["dtSess"]
GridView1.DataBind();
}
Nov 6 '07 #2
Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'.

Error is raising
Nov 6 '07 #3
Thank u kunal.its working
Nov 6 '07 #4
Plater
7,872 Expert 4TB
That's storing a lot more then you need to in the session object.
I just store the pageindex in the Session object and then if the object exists, I set the pageindex back to it on a pageload
Nov 6 '07 #5

Sign in to post your reply or Sign up for a free account.

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: news.microsoft.com | last post by:
I've looked in the help and at each of the properties for the grid view, but can't seem to find what I need. I have allowpaging set to true for my gridview and when the page loads I go and fetch...
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...
6
by: Carlos Albert | last post by:
Hi everybody, I'm working with a gridview (4 bound columns and 1 template column, using databind from codebehind). It works just fine, but I tried to add paging, and when I click any paging...
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...
8
by: AG | last post by:
ASP.NET 2.0, VS 2005 I have a gridview with paging enabled, bound to an objectdatasource. Both were dropped on to the page and configured via the wizards. Basically working as expected. The...
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: jaredciagar | last post by:
Hi Guys, Please Help ME.... I have a problem in displaying data in my gridview with paging, the data from the database is displaying to my gridview but I want to allow paging in my gridview.how can...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.