1. 程式人生 > >gridview 繫結資料來源

gridview 繫結資料來源

本人剛剛學習asp.net+c# 整理一下關於 gridview的使用

   if(!Page.IsPostBack)

{                  this.Panel1.Visible = true;
                    this.GridView1.EmptyDataText = "暫沒有資料";
                    this.GridView1.EmptyDataRowStyle.HorizontalAlign = HorizontalAlign.Center;
                    this.GridView1.DataSource = getinfomation();
                    this.GridView1.DataBind()

}

然後前臺拖拽出來一個gridview控制元件就好了,

datasource 的繫結,可以參考下我寫的小例子,我比較小白。。。(在網頁純手打了,可能會有錯誤。僅供參考)

public datatable getinfomation()

{

string sql="select xxxx from xxxxx";

return SqlHelper.ExecuteDataset(constr, CommandType.Text, sql).Tables[0];

}