很奇怪的问题,我的DataGrid的分页的链接不能被点击啊? what is your paging code behind? you need to provide a virtual record count 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void dgrdTopicList_PageIndexChanged(Object s,DataGridPageChangedEventArgs e) { intStartIndex = e.NewPageIndex * dgrdTopicList.PageSize ; dgrdTopicList.CurrentPageIndex = e.NewPageIndex; Response.Write("Changed?"); BindDataGrid(); }public void BindDataGrid() { intEndIndex = intStartIndex + dgrdTopicList.PageSize; queryString = "SELECT [Topic].* FROM [Topic] WHERE ([Topic].[TopicCatalog] = @TopicCatalog ) and (ID > @startIndex) And (ID <= @endIndex) ORDER BY subtime desc"; SqlCommand sqlCommand = new SqlCommand(queryString); sqlCommand.Parameters.Add("@TopicCatalog", System.Data.SqlDbType.Int).Value =0; sqlCommand.Parameters.Add("@startIndex", System.Data.SqlDbType.Int).Value =intStartIndex; sqlCommand.Parameters.Add("@endIndex", System.Data.SqlDbType.Int).Value =intEndIndex; DataSet dataSet; DataObj.DataSetQueryCmd(ref sqlCommand,out dataSet,"TopicList"); dgrdTopicList.DataSource=dataSet; dgrdTopicList.DataBind(); }public void Page_Load() { queryString = "SELECT [Topic].* FROM [Topic] WHERE ([Topic].[TopicCatalog] = @TopicCatalog ) ORDER BY subtime desc"; SqlCommand sqlCommand = new SqlCommand(queryString,DataObj.conn); sqlCommand.Parameters.Add("@TopicCatalog", System.Data.SqlDbType.Int).Value =0; dgrdTopicList.VirtualItemCount = ( (int)sqlCommand.ExecuteScalar() / dgrdTopicList.PageSize ); BindDataGrid(); } DataObj是我自己写的类的对象,用来数据库连接的 saucer:Response.Write("Changed?");//这句话没被执行 why (int)sqlCommand.ExecuteScalar() / dgrdTopicList.PageSize ???see数据分页的多种实现方法及性能比较http://www.ccw.com.cn/htm/center/prog/02_4_4_3_2.asp here is an example:<%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %><html><head><script language="C#" runat="server"> const String sConn = "Server=localhost;Database=NorthWind;UID=sa;PWD=;"; SqlConnection oConn= new SqlConnection(sConn); void Page_Unload(object o, EventArgs e) { oConn.Close(); } void Page_Load(Object o, EventArgs e) { oConn.Open(); if (!IsPostBack) { SqlCommand cmd = new SqlCommand("select count(*) from orders", oConn); MyDataGrid.VirtualItemCount=(int)cmd.ExecuteScalar(); BindGrid(0); } } void MyDataGrid_ChangePage(Object o, DataGridPageChangedEventArgs e) { MyDataGrid.CurrentPageIndex = e.NewPageIndex; BindGrid(e.NewPageIndex); } void BindGrid(int nPageIndex) { int nStartIndex = nPageIndex * MyDataGrid.PageSize; int nEndIndex = nStartIndex + MyDataGrid.PageSize - 1; String sSQL = "select * from (select top " + MyDataGrid.PageSize + " * from (select top " + (nEndIndex+1) + " * from orders order by orderid) t order by orderid desc) t2 order by orderid"; SqlCommand cmd = new SqlCommand(sSQL, oConn); MyDataGrid.DataSource = cmd.ExecuteReader(); MyDataGrid.DataBind(); }</script><style type="text/css">BODY {font-family:Verdana}</style></head><body> <h3>Custom Paging with DataGrid</h3> <form runat=server> <ASP:DataGrid id="MyDataGrid" runat="server" AllowPaging="True" AllowCustomPaging="True" PageSize="10" PagerStyle-Mode="NextPrev" PagerStyle-NextPageText="Forward" PagerStyle-PrevPageText="Back" PagerStyle-HorizontalAlign="Right" OnPageIndexChanged="MyDataGrid_ChangePage" BorderColor="black" BorderWidth="1" GridLines="Both" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd" AlternatingItemStyle-BackColor="#eeeeee" /> </form></body></html> 如何判断cookie变量是存在?? webrequest对象参数问题 数据源问题 安装网站后遇到的问题 net一道项目中做的问题求助^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 谁用过cuteeditor编辑器啊?能不能实现把word中的图片复制在页面内,还有明明是打了两个空格怎么显示四个的位置? dataGrid中怎么访问其中的一项 新手的笨問題 关于excel2web的问题 谁会这个???快来帮忙!!! 用xmlhttp的post方法来更新数据怎样引入身份验证? ASP.NET有没有解决不了的计算模式
{
intStartIndex = e.NewPageIndex * dgrdTopicList.PageSize ;
dgrdTopicList.CurrentPageIndex = e.NewPageIndex;
Response.Write("Changed?");
BindDataGrid();
}
public void BindDataGrid()
{
intEndIndex = intStartIndex + dgrdTopicList.PageSize;
queryString = "SELECT [Topic].* FROM [Topic] WHERE ([Topic].[TopicCatalog] = @TopicCatalog ) and (ID > @startIndex) And (ID <= @endIndex) ORDER BY subtime desc";
SqlCommand sqlCommand = new SqlCommand(queryString);
sqlCommand.Parameters.Add("@TopicCatalog", System.Data.SqlDbType.Int).Value =0;
sqlCommand.Parameters.Add("@startIndex", System.Data.SqlDbType.Int).Value =intStartIndex;
sqlCommand.Parameters.Add("@endIndex", System.Data.SqlDbType.Int).Value =intEndIndex;
DataSet dataSet;
DataObj.DataSetQueryCmd(ref sqlCommand,out dataSet,"TopicList");
dgrdTopicList.DataSource=dataSet;
dgrdTopicList.DataBind();
}
public void Page_Load()
{
queryString = "SELECT [Topic].* FROM [Topic] WHERE ([Topic].[TopicCatalog] = @TopicCatalog ) ORDER BY subtime desc";
SqlCommand sqlCommand = new SqlCommand(queryString,DataObj.conn);
sqlCommand.Parameters.Add("@TopicCatalog", System.Data.SqlDbType.Int).Value =0;
dgrdTopicList.VirtualItemCount = ( (int)sqlCommand.ExecuteScalar() / dgrdTopicList.PageSize );
BindDataGrid();
}
DataObj是我自己写的类的对象,用来数据库连接的
数据分页的多种实现方法及性能比较
http://www.ccw.com.cn/htm/center/prog/02_4_4_3_2.asp
<%@ Import Namespace="System.Data.SqlClient" %>
<html><head>
<script language="C#" runat="server">
const String sConn = "Server=localhost;Database=NorthWind;UID=sa;PWD=;";
SqlConnection oConn= new SqlConnection(sConn); void Page_Unload(object o, EventArgs e)
{
oConn.Close();
} void Page_Load(Object o, EventArgs e)
{
oConn.Open();
if (!IsPostBack)
{
SqlCommand cmd = new SqlCommand("select count(*) from orders", oConn);
MyDataGrid.VirtualItemCount=(int)cmd.ExecuteScalar(); BindGrid(0);
}
} void MyDataGrid_ChangePage(Object o, DataGridPageChangedEventArgs e)
{
MyDataGrid.CurrentPageIndex = e.NewPageIndex;
BindGrid(e.NewPageIndex);
} void BindGrid(int nPageIndex)
{
int nStartIndex = nPageIndex * MyDataGrid.PageSize;
int nEndIndex = nStartIndex + MyDataGrid.PageSize - 1;
String sSQL = "select * from (select top " + MyDataGrid.PageSize + " * from (select top " + (nEndIndex+1) + " * from orders order by orderid) t order by orderid desc) t2 order by orderid";
SqlCommand cmd = new SqlCommand(sSQL, oConn);
MyDataGrid.DataSource = cmd.ExecuteReader();
MyDataGrid.DataBind();
}
</script>
<style type="text/css">BODY {font-family:Verdana}</style>
</head>
<body>
<h3>Custom Paging with DataGrid</h3>
<form runat=server>
<ASP:DataGrid id="MyDataGrid" runat="server"
AllowPaging="True"
AllowCustomPaging="True"
PageSize="10"
PagerStyle-Mode="NextPrev"
PagerStyle-NextPageText="Forward"
PagerStyle-PrevPageText="Back"
PagerStyle-HorizontalAlign="Right"
OnPageIndexChanged="MyDataGrid_ChangePage"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
/>
</form>
</body>
</html>