0
我想添加一個webusercontol,它包含一個文本框和一個標籤到gridview控件。我使用動態數據表綁定GridView。在asp.net中添加WebUserControl到Gridview
這裏是我的代碼:
@ Register Src="CompareBox.ascx" TagName="CompareBox" TagPrefix="objCompareBox" %><br>
<asp:GridView ID="grdfoneBoxContainer" runat="server">
<Columns><br>
<asp:TemplateField HeaderText="User control"> <br>
<ItemTemplate><br>
<objCompareBox:CompareBox ID="CompareBoxCol1" runat="server"/><br>
</ItemTemplate><br>
</asp:TemplateField><br>
</Columns><br>
</asp:GridView><br>
DataTable dt = new DataTable();
dt.Columns.Add("uc1");
dt.Columns.Add("uc2");
dt.Columns.Add("uc3");
dt.Columns.Add("uc4");
CompareBox objCompareBox = new CompareBox();
objCompareBox.txt= "World";
objCompareBox.lbl = "Hello";
dt.Rows.Add(objCompareBox, objCompareBox, objCompareBox, objCompareBox);
dt.Rows.Add(objCompareBox, objCompareBox, objCompareBox, objCompareBox);
dt.Rows.Add(objCompareBox, objCompareBox, objCompareBox, objCompareBox);
dt.Rows.Add(objCompareBox, objCompareBox, objCompareBox, objCompareBox);
grdfoneBoxContainer.DataSource = dt;
grdfoneBoxContainer.DataBind();
TXT & LBL是在WebUserControl聲明瞭兩個屬性,但它給對象引用錯誤。
謝謝,