如题,谢谢!

解决方案 »

  1.   

    <script  runat="server"> 
    Sub Page_Load(Sender As Object, E As EventArgs)
            AnchorLink.NavigateUrl = "search.aspx"
                 dim dbconn as oledbconnection   
     dim dbname as string 
     dbname=server.mappath("db/data.mdb") 
     dbconn= New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source="&dbname )
     dbconn.Open()
                 dim dbcommand as oledbDataAdapter
         dim dssignin as new dataset
     dim sqlstring as string       dim  objPds as new PagedDataSource()
     sqlstring="select * from news "  
     
     dbcommand=new oledbdataAdapter(sqlstring,dbconn)
     dbcommand.fill(dssignin,"info")
     
     
                 objPds.DataSource =dssignin.Tables("info").DefaultView
                 objPds.AllowPaging=true
                 objPds.PageSize =3
                 dim CurPage as integer 
               if  not isDBNull(Request.QueryString("Page"))  then  '非空
                CurPage=Request.QueryString("Page")
       else
    CurPage=1 
        objPds.CurrentPageIndex = CurPage-1
       end if
        lblCurrentPage.Text = "当前页:" + CurPage.ToString()   
        'response.Write(Request.QueryString("Page"))
      if not objPds.IsFirstPage then
     lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1)
          end if
      
      
      if not objPds.IsLastPage then
       
    lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1) 
              end if
      
             MyRepeater.datasource=objPds
     MyRepeater.databind() 
     'response.Write(dssignin.tables("info").rows(0).item("id"))
     'if dssignin.tables("info").rows.count=0 then
     'response.Write("no record")
     'else
     'MyRepeater.datasource=objPds
     'MyRepeater.databind
     'end if
      End Sub ----------------------
    9.3.1 DataList控件的分列输出功能    DataList控件被设计为用于分列输出数据,需要输出的数据在它的<ItemTemplate>属性里,每一个<Blockquote>就是一个强制换行,每一个行内可以有多个字段的数据。绑定数据时候,使用<%# %>语法。    下面我们来看一个DataList控件的分列输出实例:
    在DataCon Web项目里新建一个 Web 窗体,命名为DataList_Sample1.aspx,并添加一个DataList控件。数据库使用StudentInfor.mdb。
     DataList控件属性设置如下 :
    <asp:DataList id="DataList1"
      runat="server" BorderColor="#3366CC"
    BorderStyle="None" BackColor="White"
    CellPadding="0" GridLines="Both"
     BorderWidth="1px" RepeatColumns="2"
      Font-Size="X-Small" Height="321px" 
    Width="432px" RepeatDirection="Horizontal">
      <SeparatorStyle BackColor="#99CCCC"></SeparatorStyle>
      <ItemStyle Font-Size="X-Small"
     ForeColor="Black" BackColor="White"></ItemStyle>
      <ItemTemplate>
        <FONT face="宋体">
    <blockquote>
    姓名:<%# DataBinder.Eval(Container.DataItem,"name") %>
    </blockquote>
    <blockquote>
    <br>编号:<%# DataBinder.Eval(Container.DataItem,"id") %>
    <br>性别:<%# DataBinder.Eval(Container.DataItem,"sex") %>
    <br>专业:<%# DataBinder.Eval(Container.DataItem,"major") %>
    <br>班级:<%# DataBinder.Eval(Container.DataItem,"class") %>
    </blockquote></FONT>
    </ItemTemplate>
    <HeaderStyle BackColor="#E0E0E0"></HeaderStyle>
    </asp:DataList>
    在DataList控件的属性里,我们需要了解的是RepeatColumns属性,其值表示数据按几列输出。
    下面是DataList_Sample1.aspx的逻辑代码部分:
      '-----code begin------
    '--省略命名空间的引用
    Public Class DataList_sample1
        Inherits System.Web.UI.Page
    #Region " Web 窗体设计器生成的代码 "
        '此处省略窗体设计器生成的代码
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    End Sub
        Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList
        '注意: 以下占位符声明是 Web 窗体设计器所必需的。
        '不要删除或移动它。
        Private designerPlaceholderDeclaration As System.Object
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
            '不要使用代码编辑器修改它。
            InitializeComponent()
    End Sub
    #End Region
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
            getdata()
    End Sub
        '读取数据
        Sub getdata()
            Dim mycon As OleDb.OleDbConnection
            Try
                mycon = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath(".") + "\StudentInfor.mdb")
                Dim mycmd As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("select *  from student", mycon)
                Dim dt As Data.DataSet = New Data.DataSet
                mycmd.Fill(dt)
                DataList1.DataSource = dt.Tables(0).DefaultView
                DataList1.DataBind()
            Catch ex As Exception
                Response.Write("程序出现错误,信息描述如下:<br>" & ex.Message.ToString)
            Finally
                mycon.Close()
            End Try
    End Sub