您的位置:首页 > 其它

GridView控件中分页显示小记

2008-04-25 14:35 405 查看
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 test_Default10 : System.Web.UI.Page
{
private int mycount = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}

protected void Bind()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=.;uid=sa;database=EastHH_Product_Quote";
con.Open();
string sqlcon = "select * from S_Bug";
SqlDataAdapter da = new SqlDataAdapter(sqlcon, con);
DataSet ds = new DataSet();
da.Fill(ds, "s");
GridView1.DataSource = ds.Tables["s"].DefaultView;
GridView1.DataBind();

}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
mycount += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"id"));
}
else
{
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = "每页小记";
e.Row.Cells[3].Text = mycount.ToString();
e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Right;
e.Row.Font.Bold = true;
}
}
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Bind();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: