我想在後面的代碼中動態創建表。我的問題是我有一個計數,我想要添加到每個TableRow多少控件之後,我想將TableRow添加到表中,然後開始一個新行。這裏是我沒有太多的代碼,但它只是增加了一行,並沒有將任何控件移動到一個單獨的新行。從服務器端創建多行表時遇到問題代碼
public void FillTable(string DB, int? appID, string function, int? rID, string UserId, int ControlsperRow)
{
OneEvaDataContext datacontext = new OneEvaDataContext();
var results = datacontext.sp_Build_Menu_Field_Names(DB, appID, function, rID);
int controlCount = 0;
TableRow tr = new TableRow();
foreach (sp_Build_Menu_Field_NamesResult result in results)
{
TableCell tcLabel = new TableCell();
TableCell TcControl = new TableCell();
Control control = new Control();
control = DynamicControlReturn.ReturnControl(result.Param_Name, result.Build_Options_Type_NAME, UserId);
control.ID = "control" + controlCount.ToString();
_controlClientIDList.Add(control.ClientID);
tcLabel.Text = result.Param_Label;
TcControl.Controls.Add(control);
tr.Cells.Add(tcLabel);
tr.Cells.Add(TcControl);
controlCount = controlCount + Convert.ToInt32(result.TD_Len);
if (controlCount == ControlsperRow)
{
base.Controls.Add(tr);
controlCount = 0;
}
}
}
我本來以爲做。新增只有當我完成構建該行的工作,但我想,因爲我使用的是相同的TableRow「TR」時,才投入只有一行。
編輯:在與上下文的基礎是我的類,它看起來像這樣:
public class Dynamic_Search_Table : System.Web.UI.WebControls.Table
{
我想你回答了你自己的問題? – womp 2010-02-22 17:47:17