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"> </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>
<!–
<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
}
}