关于DATALIST分页的问题

Python015

关于DATALIST分页的问题,第1张

让你的DropDownList调用下面的方法就行,不用点GO,或者把下面代码写道GO的事件里也行

protected void ddlPage_SelectedIndexChanged(object sender, EventArgs e)

{

GridView1.PageIndex = ((DropDownList)sender).SelectedIndex

setDataBind("")//这个事你的GridView1绑定的方法,在这里调用一下就行了

}

create proc P(@page int=1,@PageCount int=10)

as

select t1.ID,t2.Name,row=identity(int,1,1)

into #

from t1,t2

where t1.ID=t2.t1_id

create clustered index IX_#_row on #(row)

select ID,Name from # where row between (@page-1)*@PageCount+1 and @page*@PageCount

go

完整的代码如下:

<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" >

<tr>

<td height=28 ><table width="100%" height="28" cellpadding="0" cellspacing="0">

<tr>

<td background="images/bgtitbg.jpg" align="left">

<font color="#FFFFFF">

 <a href=index.asp><font color="#FFFFFF">首页</font></a><font color="#FFFFFF">>><%=common_name%></font>

</td>

</tr>

</table></td>

</tr>

<tr>

<td valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF"><br>

<%set rs=server.createobject("adodb.recordset")

rs.open sql,conn,1,1

if rs.recordcount=0 then

%>

<table width="100%" border="0" cellspacing="0" cellpadding="5" align="center">

<tr>

<td align=center>暂无信息</td>

</tr>

</table>

<%

else

rs.PageSize =30

iCount=rs.RecordCount

iPageSize=rs.PageSize

maxpage=rs.PageCount

page=request("page")

if Not IsNumeric(page) or page="" then

page=1

else

page=cint(page)

end if

if page<1 then

page=1

elseif page>maxpage then

page=maxpage

end if

rs.AbsolutePage=Page

if page=maxpage then

x=iCount-(maxpage-1)*iPageSize

else

x=iPageSize

end if

%>

<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">

<%

For i=1 To x

%>

<tr>

<td width="6%" height=24 align=center bgcolor="#FFFFFF" ><img src="images/dian3.gif"></td>

<td width="33%" height=24 bgcolor="#FFFFFF" ><a href="housesourcedetail.asp?id=<%=rs("id")%>">[<%=trim(rs("housenum"))%>]</a> <%if year(rs("update")) = year(now()) and month(rs("update"))=month(now()) and (day(rs("update"))-day(now()))=>(-3) then%><img src="images/new.gif" border="0" /><%end if%>

</td>

<td width="25%" align="center"><%=rs("household")%></td>

<td width="17%" align="center"><%=rs("district")%></td>

<td width="19%" height=24 align=center bgcolor="#FFFFFF" >

<%=year(rs("update"))&"."&month(rs("update"))&"."&day(rs("update"))%>

</td>

</tr>

<tr>

<td height=1 colspan="5"background="images/mingle/inbg.gif"></td>

</tr>

<%

rs.movenext

next

%>

</table>

<%

call PageControl(iCount,maxpage,page,"border=0 align=center","<p align=center>")

end if

rs.close

set rs=nothing

Sub PageControl(iCount,pagecount,page,table_style,font_style)

Dim query, a, x, temp

action = "http://" &Request.ServerVariables("HTTP_HOST") &Request.ServerVariables("SCRIPT_NAME")

query = Split(Request.ServerVariables("QUERY_STRING"), "&")

For Each x In query

a = Split(x, "=")

If StrComp(a(0), "page", vbTextCompare) <>0 Then

temp = temp &a(0) &"=" &a(1) &"&"

End If

Next

Response.Write("<table width=100% border=0 cellpadding=0 cellspacing=0 align=center >" &vbCrLf )

Response.Write("<form method=get onsubmit=""document.location = '" &action &"?" &temp &"Page='+ this.page.valuereturn false""><TR>" &vbCrLf )

Response.Write("<TD align=center height=35>" &vbCrLf )

Response.Write(font_style &vbCrLf )

if page<=1 then

Response.Write ("首页 " &vbCrLf)

Response.Write ("上页 " &vbCrLf)

else

Response.Write("<A HREF=" &action &"?" &temp &"Page=1>首页</A>" &vbCrLf)

Response.Write("<A HREF=" &action &"?" &temp &"Page=" &(Page-1) &">上页</A>" &vbCrLf)

end if

if page>=pagecount then

Response.Write ("下页 " &vbCrLf)

Response.Write ("尾页 " &vbCrLf)

else

Response.Write("<A HREF=" &action &"?" &temp &"Page=" &(Page+1) &">下页</A>" &vbCrLf)

Response.Write("<A HREF=" &action &"?" &temp &"Page=" &pagecount &">尾页</A>" &vbCrLf)

end if

Response.Write(" 页次:" &page &"/" &pageCount &"页" & vbCrLf)

Response.Write(" 共有" &iCount &"条新闻" & vbCrLf)

Response.Write(" 转到" &"<INPUT TYEP=TEXT CLASS=wenbenkuang NAME=page SIZE=2 Maxlength=5 VALUE=" &page &">" &"页" &vbCrLf &"<INPUT CLASS=go-wenbenkuang type=submit value=GO>")

Response.Write("</TD>" &vbCrLf )

Response.Write("</TR></form>" &vbCrLf )

Response.Write("</table>" &vbCrLf )

End Sub

%>

</td></tr>

</table>