DataList分页

datalist

:前台界面:

1:置一DataList

<asp:DataList ID="DataList1" runat="server" Width="100%" DataKeyField="mediaName" >

        <ItemTemplate>

            <table width="100%">

                <tr>

                    <td style="width: 20px; height: 22px; vertical-align: middle; text-align: left;">

                        <asp:Image ID="Image1" runat="server" ImageUrl="~/images/jt02.gif" style="text-align: left" /></td>

                    <td style="width: 300px; height: 22px; text-align: left; font-size: 12px;">

                   <%# Eval("mediaName") %>

                    </td>

                    <td style="width: auto; height: 22px">

                    </td>

                    <td style="width:100px; height: 22px;text-align: right;">

                   <a href="sourcexiangxi.aspx?medianame=<%# DataBinder.Eval(Container.DataItem,"mediaName")%>" style="font-size: 12px;"></a>

                    </td>

                </tr>

            </table>

        </ItemTemplate>

        <HeaderTemplate>

            <table width="100%" style="background-color: lightgrey">

                <tr>

                    <td style="width: 20px; height: 30px; vertical-align: middle; text-align: left;">

                        </td>

                    <td style="width: 300px; height: 30px; text-align: left; font-size: 12px;">

                       视频

                    </td>

                    <td style="width: auto; height: 30px">

                    </td>

                    <td style="width:100px; height: 30px">

                        <a href="sourcexiangxi.aspx?medianame=<%# DataBinder.Eval(Container.DataItem,"mediaName")%>" style="font-size: 12px; text-align: right;"></a>

                    </td>

                </tr>

            </table>

        </HeaderTemplate>

</asp:DataList>

2:然后放一个table在其页面

<table style="background-color:lightgrey; width:100%">

<tr>

<td style=" width:10%; height: 30px;">

   <asp:Label ID="labtotle" runat="server" style="font-weight: normal; font-size: 12px; font-family: 宋体"></asp:Label></td>

 <td style=" width:14%; height: 30px;">

  <asp:Label ID="labcurrpagenum" runat="server" style="font-weight: normal; font-size: 12px; font-family: 宋体"></asp:Label></td>

 <td style="height: 30px">

  <mp:mypaper id="MyPaper1" runat="server" backcolor="LightGray" borderwidth="0px" cellspacing="0px" firstlink="首页" height="14px" lastlink="尾页" linkistext="True" pagesize="10" style="font-weight: normal; font-size: 12px; font-family: 宋体" CurrentNumberBgColor="DodgerBlue" Width="340px" Font-Bold="False" Font-Size="12px"></mp:mypaper>

</td>

</tr>

</table>

但要在页面开始加上:

<%@ Register Assembly="page" Namespace="MyPaperControls" TagPrefix="MP" %>

 

:后台界面

public partial class source : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            fenye();

        }

    }

    private void fenye()

    {

        feny f = new feny();

        MyPaper1.RecordCount = f.countmedia();

        string aa = MyPaper1.PageTotal.ToString();

        string bb = MyPaper1.CurrentPageIndex.ToString();

        labtotle.Text = "<font color=red>" + aa + "</font>";

        labcurrpagenum.Text = "当前为<font color=red>" + bb + "</font>";

        DataSet ds = new DataSet();

        f.selectallmeida().Fill(ds, MyPaper1.DataSet_StartIndex, MyPaper1.PageSize, "table");

        this.DataList1.DataSource = ds;

        this.DataList1.DataBind();

    }

}

 

:

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

using System.Collections;

 

/// <summary>

/// feny 的摘要说明

/// </summary>

public class feny

{

    private string constring = ConfigurationManager.ConnectionStrings["ycjxdb"].ConnectionString;

       public feny()

       {

              //

              // TODO: 在此处添加构造函数逻辑

              //

       }

    public SqlDataAdapter selectallmeida()

    {

        SqlConnection con = new SqlConnection(constring);

        con.Open();

        SqlDataAdapter sda = new SqlDataAdapter("selectmedia", con);

        sda.SelectCommand.CommandType = CommandType.StoredProcedure;

        return sda;

        con.Close();

    }

    //获取总的视频数

    public int countmedia()

    {

        SqlConnection con = new SqlConnection(constring);

        con.Open();

        SqlCommand cmd = new SqlCommand("countmedia", con);

        cmd.CommandType = CommandType.StoredProcedure;

        try

        {

            int media_num = Convert.ToInt32(cmd.ExecuteScalar());

            return media_num;

        }

        catch (Exception err)

        {

            throw new System.Exception(err.Message);

        }

        finally

        {

            con.Close();

        }

    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值