1.DATALIST分页代码怎么写?
2.创建COOKIE的持久会话,他默认时间是多长?
3.用TABLE控制分页, 他里面的内容默认是居中,怎么设置他放到顶上?
4.比如做一个投票模板,怎么用图视的方式显示投票结果?是用一个控件吗?
如果会请写上代码好吗?谢谢!

解决方案 »

  1.   

    跟DataGrid的自定义分页一样做,自己找个例子看看:)
      

  2.   

    建议你下一个AspNetPager学习一下!!!
    具体看:http://www.webdiyer.com/
      

  3.   

    1.DATALIST分页代码怎么写?
    和datagrid一样
    2.创建COOKIE的持久会话,他默认时间是多长?
    默认是好像是五十年,
    3.用TABLE控制分页, 他里面的内容默认是居中,怎么设置他放到顶上?
    td valign=top
    不可以吗?不太明白你的意思
    4.比如做一个投票模板,怎么用图视的方式显示投票结果?是用一个控件吗?
    画图的方法很多种,查查资料,象这种简单的图,用table的宽度加上不同颜色就可以
      

  4.   

    datalist中的分页
    .aspx.cs
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    String strConn = ConfigurationSettings.AppSettings["strConn"];
    SqlConnection objConn = new SqlConnection(strConn);
    int curentpage;

            try
    {
    objConn.Open();
    SqlDataAdapter objdap = new SqlDataAdapter("Select * from book order by id desc",objConn);
    DataSet ds =new DataSet();
    objdap.Fill(ds);
    PagedDataSource objpds = new PagedDataSource();
    objpds.DataSource=ds.Tables[0].DefaultView;
    objpds.AllowPaging=true;
    objpds.PageSize=3;
    int bookCount = objpds.Count;
    if(Request.QueryString["Page"] !=null) 
    curentpage = Convert.ToInt32(Request.QueryString["Page"]);
    else
    curentpage=1;


    objpds.CurrentPageIndex=curentpage-1;
    lblshow.Text=">>分页:当前页:"+Convert.ToString(curentpage)+",共有"+Convert.ToString(objpds.PageCount)+"页,每页显示"+Convert.ToString(objpds.PageSize)+"条留言.";
    if (!objpds.IsFirstPage)
    lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curentpage-1);
                    else
    lnkPrev.Visible=false; if (!objpds.IsLastPage)
    lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(curentpage+1);
                    else
    lnkNext.Visible=false;
    DataList1.DataSource=objpds;
    DataList1.DataBind();

    }
    catch(Exception ex)
    {
    Response.Write(ex.Message);
    Response.End();
    }
    finally{
       if(objConn.State==ConnectionState.Open);
    objConn.Close();
    }
    }
      

  5.   

    和DataGrid的自定义分页一样做
      

  6.   

    DataList的分页技术 
    作者:孟宪会 出自:【孟宪会之精彩世界】 发布日期:2003年4月28日 5点36分48秒 
    --------------------------------------------------------------------------------
     
    由于DataList不支持内建的分页机制,因此,我们必须使用 SqlDataAdapter对象的Fill方法来实现分页,Fill方法主要用来增加或刷新DataSet的记录行。Fill方法已经被重载,我们这里选用四个参数的那个重载方法:DataSet, startRecord, maxRecords 和 TableName。<%@ Import NameSpace="System.Data.OleDb" %>
    <%@ Import NameSpace="System.Data" %>
    <HTML>
      <HEAD>
        <script language="vb" runat="server">
          Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
          If Not Page.IsPostBack() Then
          intPageSize.Text = "2"
          intCurrIndex.Text = "0"
          DataBind()
          End If
          End Sub      Private Sub DataBind()
          Dim CnString As String
          CnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
          CnString = CnString + Server.MapPath("dataDB.mdb"))
          Dim objConn As New OleDbConnection(CnString)
          Dim objDA As New OleDbDataAdapter("SELECT * FROM Document ORDER BY CreateDate DESC", objConn)
          Dim objDS As New DataSet()      If Not Page.IsPostBack() Then
          objDA.Fill(objDS)
          intRecordCount.Text = CStr(objDS.Tables(0).Rows.Count)
          objDS = Nothing
          objDS = New DataSet()
          End If      objDA.Fill (objDS, CInt(intCurrIndex.Text), CInt(intPageSize.Text), "Document")      dList.DataSource = objDS.Tables(0).DefaultView
          dList.DataBind()
          objConn.Close()
          PrintStatus()
          End Sub      Public Sub ShowFirst(ByVal s As Object, ByVal e As EventArgs)
          intCurrIndex.Text = "0"
          DataBind()
          End Sub
          Public Sub ShowPrevious(ByVal s As Object, ByVal e As EventArgs)
          intCurrIndex.Text = Cstr(Cint(intCurrIndex.Text) - CInt(intPageSize.Text))
          If CInt(intCurrIndex.Text) < 0 Then
          intCurrIndex.Text = "0"
          End If
          DataBind()
          End Sub      Public Sub ShowNext(ByVal s As Object, ByVal e As EventArgs)
          If CInt(intCurrIndex.Text) + 1 < CInt(intRecordCount.Text) Then
          intCurrIndex.Text = CStr(CInt(intCurrIndex.Text) + CInt(intPageSize.Text))
          End If
          DataBind()
          End Sub      Public Sub ShowLast(ByVal s As Object, ByVal e As EventArgs)
          Dim tmpInt as Integer      tmpInt = CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)
          If tmpInt > 0 Then
          intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - tmpInt)
          Else
          intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - CInt(intPageSize.Text))
          End If
          DataBind()
          End Sub      Private Sub PrintStatus()
          lblStatus.Text = "总记录数:<b>" & intRecordCount.Text
          lblStatus.Text += "</b> 当前:<b> "
          lblStatus.Text += CStr(CInt(CInt(intCurrIndex.Text) / CInt(intPageSize.Text)+1))
          lblStatus.Text += "</b>/<b>"      If (CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)) > 0 Then
          lblStatus.Text += CStr(CInt(CInt(intRecordCount.Text) / CInt(intPageSize.Text)+1))
          Else
          lblStatus.Text += CStr(CInt(intRecordCount.Text) / CInt(intPageSize.Text))
          End If
          lblStatus.Text += "</b>"
          End Sub
        </script>
      </HEAD>
     <body MS_POSITIONING="GridLayout">
    <TABLE height="528" cellSpacing="0" cellPadding="0" width="244" border="0"
    ms_2d_layout="TRUE">
    <TBODY>
    <TR vAlign="top">
    <TD width="244" height="528">
    <form id="Form1" method="post" runat="server">
    <TABLE height="227" cellSpacing="0" cellPadding="0" width="516" border="0"
    ms_2d_layout="TRUE">
    <TR vAlign="top">
    <TD width="10" height="15"></TD>
    <TD width="506"></TD>
    </TR>
    <TR vAlign="top">
    <TD height="48"></TD>
    <TD>
    <h2 align="center"><font face="verdana">Paging in DataList</font></h2>
    </TD>
    </TR>
    <TR vAlign="top">
    <TD height="106"></TD>
    <TD>
    <a name="this"></a>
    </TD>
    </TR>
    <TR vAlign="top">
    <TD height="19"></TD>
    <TD rowSpan="2">
    <table width="505" align="right" height="25">
    <tr>
    <td width="76%" align="left">
      <asp:label ID="lblStatus" Runat="server" Font-Name="verdana" Font-Size="10pt" />
    </td>
    <td width="6%">
      <a href="datalistpaging.aspx#this" ID="hrefFirst" onserverclick="ShowFirst" runat="server">
        <b>&lt;&lt;</b></a>
    </td>
    <td width="6%">
      <a href="datalistpaging.aspx#this" ID="hrefPrevious"
      onserverclick="ShowPrevious" runat="server">
        <b>&lt;</b></a>
    </td>
    <td width="6%">
      <a href="datalistpaging.aspx#this" ID="hrefNext" onserverclick="ShowNext" runat="server">
        <b>&gt;</b></a>
    </td>
    <td width="6%">
      <a href="datalistpaging.aspx#this" ID="hrefLast" onserverclick="ShowLast" runat="server">
        <b>&gt;&gt;</b></a>
    </td>
    </tr>
    </table>
    </TD>
    </TR>
    <TR vAlign="top">
    <TD height="19"></TD>
    <TD>
    <asp:label ID="intPageSize" Visible="False" Runat="server" /></TD>
    </TR>
    <TR vAlign="top">
    <TD height="20"></TD>
    <TD>
    <asp:label ID="intRecordCount" Visible="False" Runat="server" /></TD>
    </TR>
    <asp:DataList ID="dList" Runat="server" Width="100%"
    ItemStyle-BackColor="Beige" ItemStyle-Font-Name="宋体"
    BorderWidth="1" HeaderStyle-Font-Name="Verdana" EnableViewState="False">
    <HeaderTemplate>
    <table width="100%" style="font: 10pt verdana" cellpadding="0" cellspacing="0">
    <tr style="background-color:FF0000">
    <th align="left">
      <font color="#FFFFFF">Store ID</font></th>
    <th align="left">
      <font color="#FFFFFF">Order Number</font></th>
    <th align="left">
      <font color="#FFFFFF">Order Date</font></th>
    <th align="left">
      <font color="#FFFFFF">Qty</font></th>
    <th align="left">
      <font color="#FFFFFF">Title ID</font></th>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr style="background-color:#f5f5dc">
    <td><%# DataBinder.Eval(Container.DataItem, "id") %></td>
    <td><%# DataBinder.Eval(Container.DataItem, "Title") %></td>
    <td><%# DataBinder.Eval(Container.DataItem, "Author") %></td>
    <td><%# DataBinder.Eval(Container.DataItem, "Source") %></td>
    <td><%# DataBinder.Eval(Container.DataItem, "CreateDate") %></td>
    </tr>
    </ItemTemplate>
    <FooterTemplate>
    </TABLE>
    </FooterTemplate>
    </asp:DataList>
    <asp:label ID="intCurrIndex" Visible="False" Runat="server" />
    </TABLE>
    </FORM>
    </TD></TR>
    </TBODY>
    </TABLE>
    </body>
    </HTML> 
      

  7.   

    DataList的分页和Repeater控件的分页差不多,可以借助PagedDataSource类来实现