首先说一下,我完全是按QuickStart上面的例子来做的,做了一个自定义分页!来选择上一页、下一页,第一页和最后一页!第一页和最后一页测试正常!下一页在当前页为第一页的情况下第一次点击可以跳到第二页!但以后的点击不会动了!一直停在第二页!点击第一页不管什么时候都会跳到第一页上去!请问是什么原因?代码如下!
这是list.aspx中的datagrid定义
<asp:datagrid id="Forum_List" runat="server" CellSpacing="1" BorderWidth="0px" BorderStyle="None" AutoGenerateColumns="False" HorizontalAlign="Center" EnableViewState="False" CssClass="tablestyle1"AllowPaging="True" PageSize="30" OnPageIndexChanged="Forum_List_Page" PagerStyle-Mode="NumericPages">
…………这里显示数据列
下面是点击链接
<td align="center"><asp:label id="PageCount" runat="server" Font-Size="9pt"></asp:label>
<asp:linkbutton id="btnPrev" onclick="PagerButtonClick" runat="server" CommandArgument="prev" Text="上一页"></asp:linkbutton>
<asp:linkbutton id="btnNext" onclick="PagerButtonClick" runat="server" CommandArgument="next" Text="下一页"></asp:linkbutton>
<asp:linkbutton id="btnFirst" onclick="PagerButtonClick" runat="server" CommandArgument="0" Text="第一页"></asp:linkbutton>
<asp:linkbutton id="btnLast" onclick="PagerButtonClick" runat="server" CommandArgument="last" Text="最后一页"></asp:linkbutton>下面是.vb代码
自定义分页点击过程
Sub PagerButtonClick(ByVal sender As Object, ByVal e As EventArgs) '自定义分页
'used by external paging UI
Dim arg As String = sender.CommandArgument
Select Case arg
Case "next"
If (Forum_List.CurrentPageIndex < (Forum_List.PageCount - 1)) Then
Forum_List.CurrentPageIndex += 1
End If
Case "prev"
If (Forum_List.CurrentPageIndex > 0) Then
Forum_List.CurrentPageIndex -= 1
End If
Case "last"
Forum_List.CurrentPageIndex = (Forum_List.PageCount - 1)
Case Else
'page number
Forum_List.CurrentPageIndex = Convert.ToInt32(arg)
End Select
FillDataGrid()
End Sub
系统分页过程 Public Sub Forum_List_Page(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
Forum_List.CurrentPageIndex = e.NewPageIndex
CurrentPage = e.NewPageIndex
FillDataGrid()
End Sub数据绑定 Private Function FillDataGrid()
Dim BoardID, ClassID As Integer BoardID = Me.Request.QueryString("BoardID")
ClassID = Me.Request.QueryString("ClassID") Dim conn As Forum_Class
conn = New Forum_Class
conn.OpenConn()
Dim MyCommand As SqlDataAdapter = New SqlDataAdapter("Forum_List", conn.Myconnection)
MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@BoardID", SqlDbType.Int))
MyCommand.SelectCommand.Parameters("@BoardID").Value = BoardID MyCommand.SelectCommand.CommandType = CommandType.StoredProcedure
Dim DS As DataSet = New DataSet
MyCommand.Fill(DS, "Forum_Topic") '填充
Forum_List.DataSource = DS.Tables("Forum_Topic").DefaultView '设置数据源
Forum_List.DataBind() '绑定
conn.CloseConn() PageCount.Text = "共有 " + Forum_List.PageCount.ToString() + " 页 当前第 " + (Forum_List.CurrentPageIndex + 1).ToString() + " 页 共有帖子 " + (Forum_List.VirtualItemCount).ToString + " 篇" '分页 'Dim img As System.Web.UI.WebControls.Image = _Item.FindControl("txtQty")
End Function
十分郁闷!整了几个小时不得其解!望大家不吝指教!
这是list.aspx中的datagrid定义
<asp:datagrid id="Forum_List" runat="server" CellSpacing="1" BorderWidth="0px" BorderStyle="None" AutoGenerateColumns="False" HorizontalAlign="Center" EnableViewState="False" CssClass="tablestyle1"AllowPaging="True" PageSize="30" OnPageIndexChanged="Forum_List_Page" PagerStyle-Mode="NumericPages">
…………这里显示数据列
下面是点击链接
<td align="center"><asp:label id="PageCount" runat="server" Font-Size="9pt"></asp:label>
<asp:linkbutton id="btnPrev" onclick="PagerButtonClick" runat="server" CommandArgument="prev" Text="上一页"></asp:linkbutton>
<asp:linkbutton id="btnNext" onclick="PagerButtonClick" runat="server" CommandArgument="next" Text="下一页"></asp:linkbutton>
<asp:linkbutton id="btnFirst" onclick="PagerButtonClick" runat="server" CommandArgument="0" Text="第一页"></asp:linkbutton>
<asp:linkbutton id="btnLast" onclick="PagerButtonClick" runat="server" CommandArgument="last" Text="最后一页"></asp:linkbutton>下面是.vb代码
自定义分页点击过程
Sub PagerButtonClick(ByVal sender As Object, ByVal e As EventArgs) '自定义分页
'used by external paging UI
Dim arg As String = sender.CommandArgument
Select Case arg
Case "next"
If (Forum_List.CurrentPageIndex < (Forum_List.PageCount - 1)) Then
Forum_List.CurrentPageIndex += 1
End If
Case "prev"
If (Forum_List.CurrentPageIndex > 0) Then
Forum_List.CurrentPageIndex -= 1
End If
Case "last"
Forum_List.CurrentPageIndex = (Forum_List.PageCount - 1)
Case Else
'page number
Forum_List.CurrentPageIndex = Convert.ToInt32(arg)
End Select
FillDataGrid()
End Sub
系统分页过程 Public Sub Forum_List_Page(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
Forum_List.CurrentPageIndex = e.NewPageIndex
CurrentPage = e.NewPageIndex
FillDataGrid()
End Sub数据绑定 Private Function FillDataGrid()
Dim BoardID, ClassID As Integer BoardID = Me.Request.QueryString("BoardID")
ClassID = Me.Request.QueryString("ClassID") Dim conn As Forum_Class
conn = New Forum_Class
conn.OpenConn()
Dim MyCommand As SqlDataAdapter = New SqlDataAdapter("Forum_List", conn.Myconnection)
MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@BoardID", SqlDbType.Int))
MyCommand.SelectCommand.Parameters("@BoardID").Value = BoardID MyCommand.SelectCommand.CommandType = CommandType.StoredProcedure
Dim DS As DataSet = New DataSet
MyCommand.Fill(DS, "Forum_Topic") '填充
Forum_List.DataSource = DS.Tables("Forum_Topic").DefaultView '设置数据源
Forum_List.DataBind() '绑定
conn.CloseConn() PageCount.Text = "共有 " + Forum_List.PageCount.ToString() + " 页 当前第 " + (Forum_List.CurrentPageIndex + 1).ToString() + " 页 共有帖子 " + (Forum_List.VirtualItemCount).ToString + " 篇" '分页 'Dim img As System.Web.UI.WebControls.Image = _Item.FindControl("txtQty")
End Function
十分郁闷!整了几个小时不得其解!望大家不吝指教!
解决方案 »
- 根据ID怎么获取详细信息?????linq问题!
- 如何用JavaScript获取控件CommandArgument属性的值?(内附详细说明)
- 求解动态生成控件的问题
- 最新第一报道:java被强奸了!!!!!!
- window server 2003 iis 建设中问题
- 甩分了!!!关于TREE VIEW如何实现只允许鼠标选择节点,键盘无效?
- 如何在*.aspx页面文件中直接嵌入C#代码以实现查找文件功能?
- JAVASCRIPT 里的删除数据怎么写
- 求救!VS.NET的安装过程出错!
- 请问怎样在DataList中实现象DataGrid那样的分页功能?
- TabStrip和MultiPage控件问题,高手请进
- 基础连接已经关闭,无法连接到远程服务器!
要把代码写到
If (Not IsPostBack) ThenEnd If
中去
If (Not IsPostBack) Then
FillDataGrid()
End If
End Sub这样写了之后系统的那个分页点击数据就没会出来了!自定义分页也无效果!何故?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Not IsPostBack) Then
FillDataGrid()
End If
End Sub只能显示首页了!点击第后面的页码都显示不了数据是空的!难道我代码有错??新手上路,有什么不对的还请指点指点哈
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %><script runat=server>
SqlConnection conNorthwind;
string strSelect;
int intStartIndex;
int intEndIndex;void Page_Load(Object sender , EventArgs e)
{
SqlCommand cmdSelect; conNorthwind = new SqlConnection( @"Server=localhost;Integrated Security=SSPI;Database=Northwind" );
if (! IsPostBack )
{
// Get Total Pages
strSelect = "Select Count(*) From Products";
cmdSelect = new SqlCommand( strSelect, conNorthwind );
conNorthwind.Open();
dgrdProducts.VirtualItemCount = ( (int)cmdSelect.ExecuteScalar() / dgrdProducts.PageSize );
conNorthwind.Close();
BindDataGrid();
}
}void BindDataGrid ()
{
SqlDataAdapter dadProducts;
DataSet dstProducts; intEndIndex = intStartIndex + dgrdProducts.PageSize;
strSelect = "Select * From Products Where ProductID > @startIndex And ProductID <= @endIndex Order By ProductID";
dadProducts = new SqlDataAdapter( strSelect, conNorthwind );
dadProducts.SelectCommand.Parameters.Add( "@startIndex", intStartIndex );
dadProducts.SelectCommand.Parameters.Add( "@endIndex", intEndIndex );
dstProducts = new DataSet();
dadProducts.Fill( dstProducts ); dgrdProducts.DataSource = dstProducts;
dgrdProducts.DataBind();
}void dgrdProducts_PageIndexChanged( object s, DataGridPageChangedEventArgs e ) {
intStartIndex = ( e.NewPageIndex * dgrdProducts.PageSize );
dgrdProducts.CurrentPageIndex = e.NewPageIndex;
BindDataGrid();
}</Script><html>
<head><title>DataGridCustomPaging.aspx</title></head>
<body>
<form Runat="Server"><asp:DataGrid
ID="dgrdProducts"
AllowPaging="True"
AllowCustomPaging="True"
PageSize="3"
OnPageIndexChanged="dgrdProducts_PageIndexChanged"
PagerStyle-Mode="NumericPages"
CellPadding="3"
Runat="Server" /></form>
</body>
</html>