手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

GridView 分页导航

来源:互联网 作者:west263.com 时间:2008-02-22
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

runat="server">首 页</asp:LinkButton>&nbsp;<asp:LinkButton ID="btnPrev" CommandArgument="prev" OnClick="PagerButtonClick" runat="server">上一页</asp:LinkButton>
<asp:LinkButton ID="btnNext" CommandArgument="next" OnClick="PagerButtonClick" runat="server">下一页</asp:LinkButton>
<asp:LinkButton ID="btnLast" CommandArgument="last" OnClick="PagerButtonClick" runat="server">尾 页</asp:LinkButton>
<asp:Label ID="LblCurrentIndex" runat="server"></asp:Label>
<asp:Label ID="LblPageCount" runat="server"></asp:Label>
<asp:Label ID="LblRecordCount" runat="server"></asp:Label>
跳转到第<asp:DropDownList ID="ddlCurrentPage" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>页</td> <tr>
<td style="width: 569px">
&nbsp;操作:
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="删除合作商" />
</td>
</tr>
</table>
</form>
</body>
</html>
CS:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

public partial class StfCmpManager : System.Web.UI.Page
...{
protected void Page_Load(object sender, System.EventArgs e)
...{

string StfRight = "";
// 在此处放置用户代码以初始化页面 http://www.knowsky.com
if (Session["UserId"] == null)
...{
Response.Write("<script language='javascript'>alert('工作超时,请重新登录。');top.window.location='default.aspx';</script>");
return;
}
else
...{
StfRight = Session["UserRight"].ToString().Trim();

if (!this.IsPostBack)
...{

if (StfRight != "7" && StfRight != "8")
...{
Response.Write("<script language='javascript'>alert('你没有权限察看此页。');top.window.location='default.aspx';</script>");
return;
}

GridViewBind("");
}
}

}
private void GridViewBind(string Sqlsort)
...{
string where = string.Empty;
where = "and a.StfRight='6' and a.StfId=b.Stfid";
if (TStfName.Text.Trim() != "")
...{
where = " and a.StfCmpName like '%" TStfName.Text.Trim() "%'";
}


if (StartTime.Text.Trim() != "")
...{
where = " and a.StfRegistertime >= '" StartTime.Text "'";
}
if (EndTime.Text.Trim() != "")
...{
where = " and a.StfRegistertime <= '" EndTime.Text "'";
}

if (where != string.Empty)
...{
where = "Where " where.Substring(4);
}
string connStr = ConfigurationManager.AppSettings.Get("DataConnectionString");
string SqlStr = "Select a.StfId as StfId,a.StfName as StfName,a.StfRealName as StfRealName,a.StfCmpName as StfCmpName,b.StfCmpMoney as StfCmpMoney,b.StfQbmoney as StfQbmoney,a.StfRegistertime as StfRegistertime From TStafferInfo a,TCmpMoney b " where Sqlsort;
//Response.Write(SqlStr);
//Response.End();
DataSet ds = new DataSet();

try
...{
SqlConnection conn = new SqlConnection(connStr);
if (conn.State.ToString() == "Closed") conn.Open();

SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
da.Fill(ds, "TStafferInfo");
if (conn.State.ToString() == "Open") conn.Close();

GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();

LblCurrentIndex.Text = "第 " (GridView1.PageIndex 1).ToString() " 页";
LblPageCount.Text = "共 " GridView1.PageCount.ToString() " 页";
LblRecordCount.Text = "总共 " ds.Tables[0].Rows.Count.ToString() " 条";
if (ds.Tables[0].Rows.Count == 0)
...{
btnFirst.Visible = false;
btnPrev.Visible = false;
btnNext.Visible = false;
btnLast.Visible = false;

LblCurrentIndex.Visible = false;
LblPageCount.Visible = false;

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!