asp.net中DataGridView的常用用法
asp.net中DataGridView的常用用法
2008-09-03
DataGridView的常用用法 //读取表Supplier并绑定到GridView中
private void BindGvSupplier()
...{
OracleConnection conn = this.Conn();
OracleCommand cmd = new OracleCommand( "select * from Supplier ", conn);
OracleDataAdapter sda = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "Supplier ");
string[] SuppId = new string[ds.Tables[ "Supplier "].Rows.Count];
for (int i = 0; i <ds.Tables[ "Supplier "].Rows.Count; i++)
...{
SuppId[i] = ds.Tables[ "Supplier "].Rows[i][0].ToString();
}
this.gvSupplier.DataSource = ds.Tables[ "Supplier "];
this.gvSupplier.DataKeyNames[0] = "SuppId ";
this.gvSupplier.DataBind();
this.lblPageIndex.Text = Convert.ToString(int.Parse(this.gvSupplier.PageIndex.ToString()) + 1);
this.lblTotalPage.Text = this.gvSupplier.PageCount.ToString();
this.lblCount.Text = this.GetTotalCount().ToString();
}
//分页触发的事件
protected void gvSupplier_PageIndexChanging(object sender, GridViewPageEventArgs e)
...{
this.gvSupplier.PageIndex = e.NewPageIndex;
this.BindGvSupplier();
this.lblPageIndex.Text = Convert.ToString(int.Parse(this.gvSupplier.PageIndex.ToString()) + 1);
this.cbAllSelect_CheckedChanged(this.cbAllSelect, e);
}