在aspx 页面内,GridView的RowDataBound绑定问题:
在aspx页面中,利用GridView控件实行数据绑定
后台代码示例:
protected void Page_Load(object sender, EventArgs e)
{
connString = ConnectionString.ReturnConnString();
BindGridView();
}
// 绑定GridView
private void BindGridView()
{
DataTable countdt = OracleAccess.ExecuteDataSet(connString, CommandType.Text, countStr, null).Tables[0];
DataTable dt = OracleAccess.ExecuteDataSet(connString, CommandType.Text, strSQL, null).Tables[0];
thisPage.Text = nowPage.ToString();
if (dt.Rows.Count > 0)
{
//获取总数
int allcount = int.Parse(countdt.Rows[0]["ALLCOUNT"].ToString());
//分页
double pas = (double)allcount / (double)pageCount;
allPages = (int)Math.Ceiling(pas);
this.allPage.Text = allPages.ToString();
this.pageNum.Text = pageCount.ToString();
thisPageNum.Text = dt.Rows.Count.ToString();
this.JFGL_DATA.DataSource = dt;
this.JFGL_DATA.DataBind();
}
else
{
//数据为空,构造结构
BindNullGV();
}
}
// 初始化GridView
private void BindNullGV()
{
DataTable dt = MakeNullTable();
if (dt.Rows.Count == 0)
{
dt.Rows.Add(dt.NewRow());
}
JFGL_DATA.DataSource = dt;
JFGL_DATA.DataBind();
}
// 构造临时表
private DataTable MakeNullTable()
{
DataTable dt = new DataTable("NullTable");
DataColumn column0 = new DataColumn("xx");
column0.DataType = System.Type.GetType("System.String");
DataColumn column1 = new DataColumn("ID");
column1.DataType = System.Type.GetType("System.St