| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 587 人关注过本帖
标题:datalist分页问题?
只看楼主 加入收藏
jingzhisen
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-8-30
收藏
 问题点数:0 回复次数:0 
datalist分页问题?
<%@ Page Language="VB" AutoEventWireup="true"  CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www. >
<head id="Head1" runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
<div>
         <asp:DataList ID="DataList1" runat="server" CellPadding="3" RepeatColumns="4" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellSpacing="2" GridLines="Both" Height="210px" Width="738px">
           <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
           <ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
           <ItemTemplate><a href="ViewRecDetail.aspx?sid=1&dcode=GENERAL&sysid=<%# Eval("SYSID") %>">
                                            <img src="ViewThumb.aspx?sid=1&dcode=GENERAL&sysid=<%# Eval("SYSID") %>" alt="" border="0" style="border: solid 1px #333333;" /></a> <br />
                                            &nbsp;&nbsp; &nbsp;&nbsp;<a href="ViewRecDetail.aspx?sid=1&dcode=GENERAL&sysid=<%# Eval("SYSID") %>"><asp:Label ID="lblname" runat="server" Text='<%# Eval("女将姓名") %>' ></asp:Label></a><br />
                                             <asp:Label ID ="lblshidai" runat ="server" Text='<%#Eval("时代") %>' Font-Size="Small"></asp:Label>&nbsp;&nbsp; <asp:Label ID ="lbljunxian" runat ="server" Text='<%#Eval("军衔") %>' Font-Size="Small"></asp:Label>
                                               &nbsp;&nbsp;<asp:Label ID ="lblguoji" runat ="server" Text='<%#Eval("国籍") %>' Font-Size="Small"></asp:Label>
                                          
                                            </ItemTemplate>
           <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
           <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
       </asp:DataList></div>
        <br />
        共<asp:Label ID="lb_count" runat="server" Text="Label"></asp:Label>条记录
        &nbsp; &nbsp; &nbsp; 共<asp:Label ID="lb_page" runat="server" Text="Label"></asp:Label>页 &nbsp;
        &nbsp; 当前第<asp:Label ID="lb_CurrentPage" runat="server" Text="1"></asp:Label>页&nbsp; &nbsp;
        &nbsp; &nbsp;
        <asp:LinkButton ID="LinkFirst" runat="server" OnClick="LinkFirst_Click">第一页</asp:LinkButton>&nbsp; &nbsp;
        <asp:LinkButton ID="LinkUp" runat="server" OnClick="LinkUp_Click">上一页</asp:LinkButton>
        &nbsp; &nbsp;
        &nbsp; &nbsp;<asp:LinkButton ID="LinkDown" runat="server" OnClick="LinkDown_Click">下一页</asp:LinkButton>
        &nbsp; &nbsp;<asp:LinkButton ID="LinkLast" runat="server" OnClick="LinkLast_Click">最后一页</asp:LinkButton>
        &nbsp; &nbsp;转到第<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
        </asp:DropDownList>页
      
   
    </form>
</body>
</html>


Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim ConnStr As String = "server=localhost;database=GENERAL;uid=sa;pwd=123"
    Dim conn As New SqlConnection(ConnStr)
    Dim com As New SqlCommand
    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        GetPageCount()
    End Sub
    Sub GetPageCount()
     

        conn.Open()
        com = New SqlCommand("Select SYSID,女将姓名,军衔,时代,国籍 from MDLS_Literature_Metadata  where 时代='近现代'", conn)
        Dim da As New SqlDataAdapter(com)
        Dim ds As New DataSet()
        da.Fill(ds, "table")
        conn.Close()
        Dim cup As Integer = CInt(lb_CurrentPage.Text)
        Dim ps As New PagedDataSource
        ps.DataSource = ds.Tables("table").DefaultView
        ps.AllowPaging = "True"
        ps.PageSize = 8
        ps.CurrentPageIndex = cup - 1
        lb_count.Text = ps.DataSourceCount.ToString
        lb_page.Text = ps.PageCount.ToString

        If Not IsPostBack Then
            Dim i As Integer
            For i = 1 To ps.PageCount
                DropDownList1.Items.Add(i.ToString())
            Next
            LinkUp.Enabled = "True"
            LinkDown.Enabled = "True"
        End If
        Try
            DropDownList1.SelectedItem.Text = cup.ToString
            DataList1.DataSource = ps
            DataList1.DataBind()

        Catch ex As Exception
            Throw ex
        End Try
      


    End Sub

    Protected Sub LinkFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkFirst.Click
        If CInt(lb_CurrentPage.Text) = 1 Then
            MsgBox("已经是第一页了!")
        Else
            lb_CurrentPage.Text = "1"
            GetPageCount()
        End If
      

    End Sub
    Protected Sub LinkUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkUp.Click
        If CInt(lb_CurrentPage.Text) > 1 Then
            lb_CurrentPage.Text = "3"
            DropDownList1.SelectedValue = lb_CurrentPage.Text
        Else
            MsgBox("已经是第一页了")
        End If
        GetPageCount()

    End Sub
    Protected Sub LinkDown_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkDown.Click
        Try
           
            lb_CurrentPage.Text = CStr(CInt(lb_CurrentPage.Text) + 1)
            DropDownList1.SelectedValue = lb_CurrentPage.Text
            GetPageCount()
        Catch ex As Exception
         
            lb_CurrentPage.Text = "8"
            GetPageCount()
        End Try
     
    End Sub
    Protected Sub LinkLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkLast.Click
        If (lb_CurrentPage.Text.ToString() <> lb_page.Text.ToString()) Then
            lb_CurrentPage.Text = lb_page.Text.ToString()
        Else
            Response.Write("已经是最后一页")
        End If
        GetPageCount()
    End Sub
    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Dim page As Integer
        page = Convert.ToInt16((DropDownList1.SelectedItem.Value))
        lb_CurrentPage.Text = page.ToString()
        GetPageCount()
    End Sub
End Class
搜索更多相关主题的帖子: datalist 
2009-08-30 16:15
快速回复:datalist分页问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031961 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved