我從數據庫中獲取記錄列表並將其存儲在DataTable
,然後將其轉化爲System.Web.UI.WebControls.Table
增加無線電控制的C#表
後,添加一個單選按鈕控件System.Web.UI.HtmlControls.HtmlInputRadioButton
每個Table
行。
,但我在網上收到錯誤的Object reference not set to an instance of an object.
tOutput.RenderControl(new HtmlTextWriter(sw));
代碼:
string sReturn = "";
Table tOutput;
HtmlInputRadioButton rdoProperty;
StringWriter sw = new StringWriter();
try
{
DataTable dtOutput = new DataTable();
dtOutput = IstaDAL.getPropertyList(sProjectID);
if (dtOutput.Rows.Count > 0)
{
tOutput = convertDataTable2HTMLTable(dtOutput, true, true, false);
foreach(TableRow trOutput in tOutput.Rows)
{
if (trOutput.TableSection == TableRowSection.TableBody)
{
rdoProperty = new HtmlInputRadioButton();
rdoProperty.Attributes["value"] = trOutput.Cells[1].Text;
rdoProperty.Attributes["name"] = "rdoProperty";
trOutput.Cells[0].Controls.Add(rdoProperty);
}
}
tOutput.RenderControl(new HtmlTextWriter(sw));
sReturn = sw.ToString();
}
}
編輯:
當我試圖進去rdoProperty
做了一些研究,我發現他的一個財產get_RenderedNameAttribute
導致該異常
堆棧跟蹤:
at System.Web.UI.HtmlControls.HtmlInputRadioButton.get_RenderedNameAttribute()
是否'convertDataTable2HTMLTable()''返回任何null'條件下,想出了? –
@GrantWinney:不,它不。實際上,它返回'HtmlTable',正如我可以在'trOutput.Cells [1] .Text;'中看到的值每次迭代 – Shaggy