分享
 
 
 

DataList 控件分页操作!

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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="admin/style/item.css" type="text/css" rel="stylesheet">

<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="../images/r_7_11.jpg"></td>

<td valign="middle" bgcolor="#fecc00" align="center"><a href='<%# DataBinder.Eval(Container.DataItem,"id","radio_nj_info.aspx?id={0}") %>'>

<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="../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()

{

int i;

int len = Convert.ToInt32(Math.Ceiling(Convert.ToInt32(ViewState["pcount"]) / 10));

float f = Convert.ToSingle(ViewState["pcount"]) / 10 ;

if(f > Convert.ToInt32(Convert.ToInt32(ViewState["pcount"]) / 10))

{

len = len + 1;

}

this.p_pagelist.Controls.Clear();

string s = "";

//int curpage = Convert.ToInt32(ViewState["curpage"]);

for(i=1;i<=len;i++)

{

System.Web.UI.WebControls.LinkButton lkbtn = new LinkButton();

s = " " + i.ToString() + " ";

lkbtn.Text = s;

lkbtn.CommandArgument = i.ToString();

this.p_pagelist.Controls.Add(lkbtn);

lkbtn.Command += new CommandEventHandler(lkbtn_Command);

}

}

private void Clear_LinkButton_Style()

{

int curpage = Convert.ToInt32(ViewState["curpage"])+1;

foreach(Control ictrl in this.p_pagelist.Controls)

{

if(ictrl.GetType().ToString().ToUpper().IndexOf("LINKBUTTON")>0)

{

LinkButton ilkbtn = (LinkButton)ictrl;

if(ilkbtn.CommandArgument.ToString() == curpage.ToString())

{

ilkbtn.CssClass = "bigsize";

}

else

{

ilkbtn.CssClass ="normal";

}

}

}

}

private void lkbtn_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)

{

int gos,sIndex;

int len = Convert.ToInt32(Math.Ceiling(Convert.ToInt32(ViewState["pcount"]) / 10));

if(e.CommandArgument == null)

{

return;

}

sIndex = 0;

gos = Convert.ToInt32(e.CommandArgument);

//Clear_LinkButton_Style();

//LinkButton lkbtn = (LinkButton)sender;//

//lkbtn.CssClass = "bigsize";

if(gos<=0)

{

sIndex = 0;

}

else

{

if(gos>= len + 1)

{

sIndex = len;

}

else

{

sIndex = gos-1;

}

}

ViewState["curpage"] = sIndex;

Bind_List();

}

/**

private void Go_TO_Click(object sender, System.EventArgs e)

{

int gos,sIndex;

int len = Convert.ToInt32(Math.Ceiling(Convert.ToInt32(ViewState["pcount"]) / 9));

if(atTxt.Text == "")

{

return;

}

sIndex = 0;

gos = Convert.ToInt32(atTxt.Text);

if(gos<=0)

{

sIndex = 0;

}

else

{

if(gos>= len + 1)

{

sIndex = len;

}

else

{

sIndex = gos-1;

}

}

ViewState["curpage"] = sIndex;

Bind_List();

}

**/

/// <summary>

/// 取得NJ娱乐信息

/// </summary>

/// <param name="t"></param>

/// <param name="i"></param>

/// <returns></returns>

public string Return_Nj_Detail(string t,int i)

{

string rstr=null;

string[] istr = t.Split(',');

rstr = istr[i];

return rstr;

}

#region Web 窗体设计器生成的代码

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

this.p0.Command += new System.Web.UI.WebControls.CommandEventHandler(this.go_page);

this.p1.Command += new System.Web.UI.WebControls.CommandEventHandler(this.go_page);

this.p2.Command += new System.Web.UI.WebControls.CommandEventHandler(this.go_page);

this.p3.Command += new System.Web.UI.WebControls.CommandEventHandler(this.go_page);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有