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];

}

猜你喜欢

转载自blog.csdn.net/weixin_43092856/article/details/84529840