GridView控件中分页显示小记

来源:互联网 发布:登陆微博显示网络出错 编辑:程序博客网 时间:2024/05/20 07:51

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();
    }
}

原创粉丝点击