【发布时间】:2012-01-20 16:43:44
【问题描述】:
我在用户控件中有一个 gridview。我在 usercontrol 构造函数中新建了这个定义为类字段的 gridview。在 Page_Init 中,我设置了必要的属性,如 ID、宽度等。我还在同一事件中将网格添加到 usercontrol 的 Control 集合中。我也有一个重定向属性和方法,这里是相关的:
public void DataBind()
{
_grv.DataBind();
}
//here is the datasource
public object DataSource
{
get{ return _grv.DataSource; }
set{ _grv.DataSource = value; }
}
我在我的网页中这样调用数据绑定成员:
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
return;
DataTable table = new DataTable();
DataColumn col1 = new DataColumn();
DataColumn col2 = new DataColumn();
DataColumn col3 = new DataColumn();
table.Columns.Add(col1);
table.Columns.Add(col2);
table.Columns.Add(col3);
DataRow row1 = table.NewRow();
DataRow row2 = table.NewRow();
DataRow row3 = table.NewRow();
row1[0] = "row1";
row1[1] = "value";
row1[2] = "amount";
row2[0] = "row2";
row2[1] = "no value";
row2[2] = "no amount";
row3[0] = "row3";
row3[1] = "values";
row3[2] = "amounts";
table.Rows.Add(row1);
table.Rows.Add(row2);
table.Rows.Add(row3);
ucManagement.DataSource = table;
ucManagement.DataBind();
}
但在回发时_grv.DataSource 为空。怎么了?
【问题讨论】:
标签: c# asp.net data-binding gridview