当前位置:编程学习 > asp >>

DataList 控件分页操作

答案:aspx 源文件

<%@ Page language="c#" Codebehind="radionj_list.aspx.cs" AutoEventWireup="false" Inherits="radio.radio.radionj_list" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>NJ列表</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="javascript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href=><style>
.normal
{
font-weight:normal
}
.bigsize
{
font-weight:bold;
}

<!-- asthlon发表于 05 3-25 -->
</style>

</HEAD>
<body MS_POSITIONING="GridLayout"> <!--<table border="0" cellspacing="0" cellpadding="0">

</table>-->
<form id="Form1" method="post" runat="server">
<div align="center">
<asp:datalist id="info_data" runat="server" ShowFooter="False" GridLines="Both" BorderColor="Control"
RepeatColumns="2" RepeatDirection="Horizontal" HorizontalAlign="Center" ShowHeader="False"
CellPadding="5" BorderWidth="0px" RepeatLayout="Flow">
<ItemStyle HorizontalAlign="Center" Height="120px" Width="140px" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<table cellspacing="0" cellpadding="0">
<tr>
<td><img src=http://old.zzzyk.com/article/Article/".images/r_7_11.jpg"></td>
<td valign="middle" bgcolor="#fecc00" align="center"><a href=><div style="overflow:hidden;width:90px;height:90px;"><img width=90 src='<%# Return_Nj_Detail((string)DataBinder.Eval(Container.DataItem,"content"),1)%>'></div>
</a>
</td>
<Td><img src=http://old.zzzyk.com/article/Article/".images/r_7_13.jpg"></Td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
<div style="PADDING-LEFT:40px"><FONT color="#000000">共
<asp:label id="list_num" runat="server"></asp:label>条记录</FONT>
<asp:label id="list_at" runat="server"></asp:label><FONT color="#000000">&nbsp;</FONT><asp:linkbutton id="p0" runat="server" CommandName="p0"><font face="Webdings">9</font></asp:linkbutton>
<asp:linkbutton id="p1" runat="server" CommandName="p1">
<font face="Webdings">7</font></asp:linkbutton>
[<asp:PlaceHolder id="p_pagelist" runat="server"></asp:PlaceHolder>]
<asp:linkbutton id="p2" runat="server" CommandName="p2">
<font face="Webdings">8</font></asp:linkbutton>
<asp:linkbutton id="p3" runat="server" CommandName="p3">
<font face="Webdings">:</font></asp:linkbutton>
<!--
&nbsp;<asp:textbox id="atTxt" onkeyup="this.value=this.value.replace(/\D/g,'')" runat="server" Width="35px"
onafterpaste="this.value=this.value.replace(/\D/g,'')"></asp:textbox><asp:button id="Go_TO" runat="server" Text="GO"></asp:button>
-->
</div>
</div>
</form>
</body>
</HTML>


.cs 源文件

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace radio.radio
{
/// <summary>
/// asthlon发表于 05 3-25。
/// </summary>
public class radionj_list : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList info_data;
protected System.Web.UI.WebControls.Label list_num;
protected System.Web.UI.WebControls.Label list_at;
protected System.Web.UI.WebControls.LinkButton p0;
protected System.Web.UI.WebControls.LinkButton p1;
protected System.Web.UI.WebControls.LinkButton p2;
protected System.Web.UI.WebControls.PlaceHolder p_pagelist;
protected System.Web.UI.WebControls.LinkButton p3;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
WebUse.SqlEC.DataBase dItem = new WebUse.SqlEC.DataBase();
string sql = "select count(id) from radio_dj";
ViewState["curpage"] = 0;
ViewState["pcount"] = dItem.StrSql_TxtSql(sql);
Bind_List();
Post_Control();
}
else
{
Post_Control();
}
// 在此处放置用户代码以初始化页面
}
private void Bind_List()
{
int Psize = 10;
int sIndex,len,at;
float f;
WebUse.SqlEC.DataBase dItem = new WebUse.SqlEC.DataBase();
len = Convert.ToInt32(Math.Ceiling(Convert.ToInt32(ViewState["pcount"]) / Psize));//+1
f = Convert.ToSingle(ViewState["pcount"]) / Psize ;
if(f > Convert.ToInt32(Convert.ToInt32(ViewState["pcount"]) / Psize))
{
len = len + 1;
}


sIndex = Convert.ToInt32(ViewState["curpage"]) * Psize;
SqlDataAdapter adp = new System.Data.SqlClient.SqlDataAdapter();
DataSet ds = new DataSet();
adp = dItem.Read_Adapter_NoArg("radio_dj_sel");//dItem.Read_Adapter_TxtSql(sql);
adp.Fill(ds,sIndex,Psize,"show");
info_data.DataSource = ds;
info_data.DataBind();

at = Convert.ToInt32(ViewState["curpage"]);
if(at <=0)
{
p0.Enabled = false;
p1.Enabled = false;
}
else
{
p1.Enabled = true;
p0.Enabled = true;
}
if(at >= len-1)
{
p2.Enabled = false;
p3.Enabled = false;
}
else
{
p2.Enabled = true;
p3.Enabled = true;
}
list_num.Text = Convert.ToString(ViewState["pcount"]);
list_at.Text = Convert.ToString(sIndex / Psize + 1) + "/" + len.ToString() ;
Clear_LinkButton_Style();
}
private void go_page(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{
string cmdName;
int sIndex = Convert.ToInt32(ViewState["curpage"]);
int len = Convert.ToInt32(Math.Ceiling(Convert.ToInt32(ViewState["pcount"]) / 10));
cmdName = e.CommandName;
switch(cmdName)
{
case "p0":
sIndex = 0;
break;
case "p1":
sIndex -= 1;
break;
case "p2":
sIndex +=1;
break;
case "p3":
sIndex = len;
break;
}
ViewState["curpage"] = sIndex;
Bind_List();
}

private void Post_Control()<

上一个:ASP防注入之解决方案--加强版
下一个:动态模板列更新数据分页的例子

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,