-1
我有一個gridview內的用戶控件。我新的這個gridview被定義爲usercontrol構造函數中的類字段。在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
爲空。哪裏不對?
是什麼?你有沒有讀過我的問題?你在說什麼?我知道網格在第一次綁定後不需要數據源,這正是我的問題所在!它不保留它! – jim
還有一件事,正如我在Magnus中所說的那樣,他的解決方案不起作用。 – jim
@jim爲什麼如此敵對?我們正試圖在這裏幫助你。順便說一句,你的評論沒有任何意義。你顯然理解GridView不再需要數據源,但不能理解爲什麼它不能保持它。 – Magnus