「グリッド システム」を使用して、動的に作成されたコントロール (ユーザーの選択に基づいて条件付きで作成) を Web ページに格納したいと考えています。私はhtmlテーブルとコントロールを作成してから、コントロールをhtmlテーブルの行セルに追加しています。
問題は、(WPF の「スパン」カウントと同様に) 長い文字列など、複数のセルにいくつかのコントロールをスパンできるようにすることです。
このコード:
protected override void CreateChildControls()
{
base.CreateChildControls();
LiteralControl message = new LiteralControl();
message.Text = DisplayMessage;
Controls.Add(message);
int selectionMadeOnEditor = 0; // TODO: Make this dynamic; this is just for testing
HtmlTable tbl = null;
switch (selectionMadeOnEditor)
{
case 0:
tbl = GeneratePlatypoisons();
break;
case 1:
//Console.WriteLine(5);
break;
default:
tbl = GenerateMorayEelLikeElectricity();
break;
}
this.Controls.Add(tbl);
. . .
private HtmlTable GeneratePlatypoisons()
{
HtmlTable dynamicTable = new HtmlTable();
// Create Row 1
var row = new HtmlTableRow();
var cell1 = new HtmlTableCell();
var cell2 = new HtmlTableCell();
var cell3 = new HtmlTableCell();
var cell4 = new HtmlTableCell();
var cell5 = new HtmlTableCell();
var cell6 = new HtmlTableCell();
row.Cells.Add(cell1);
row.Cells.Add(cell2);
row.Cells.Add(cell3);
row.Cells.Add(cell4);
row.Cells.Add(cell5);
row.Cells.Add(cell6);
dynamicTable.Rows.Add(row);
// Populate row 1
LiteralControl section1Hdr = new LiteralControl("<h2>Section 1: Platypus Information</h2>");
LiteralControl section2Hdr = new LiteralControl("<h2>Section 2: PoisonToe Information</h2>");
cell1.Controls.Add(section1Hdr);
cell5.Controls.Add(section2Hdr);
// Create Row 2
var row2 = new HtmlTableRow();
var cell2_1 = new HtmlTableCell();
var cell2_2 = new HtmlTableCell();
var cell2_3 = new HtmlTableCell();
var cell2_4 = new HtmlTableCell();
var cell2_5 = new HtmlTableCell();
var cell2_6 = new HtmlTableCell();
row2.Cells.Add(cell2_1);
row2.Cells.Add(cell2_2);
row2.Cells.Add(cell2_3);
row2.Cells.Add(cell2_4);
row2.Cells.Add(cell2_5);
row2.Cells.Add(cell2_6);
dynamicTable.Rows.Add(row2);
// Populate Row 2
LiteralControl reqDateStr = new LiteralControl("PoisonToe Date:");
cell2_1.Controls.Add(reqDateStr);
boxRequestDate = new TextBox();
boxRequestDate.Text = DateTime.Today.ToShortDateString();
cell2_2.Controls.Add(boxRequestDate);
LiteralControl payAmtStr = new LiteralControl("Platypus Amount:");
cell2_3.Controls.Add(payAmtStr);
boxPaymentAmount = new TextBox();
cell2_4.Controls.Add(boxPaymentAmount);
LiteralControl reqNameStr = new LiteralControl("PoisonToe Name:");
cell2_5.Controls.Add(reqNameStr);
boxRequestorName = new TextBox();
cell2_6.Controls.Add(boxRequestorName);
// Populate row 3
// Populate row 4
// Populate row 5
// Populate row 6
// Populate row 7
return dynamicTable;
}
リテラル コントロール/文字列を cell1 と cell5 に追加しました。
cell1.Controls.Add(section1Hdr);
cell5.Controls.Add(section2Hdr);
...最初のセルがセル 1 から 4 にまたがり、2 番目のセルがセル 5 と 6 にまたがることを期待していますが、次のように実行できません。
これらの弦がけいれんに詰め込まれてガタガタになるのではなく、これらの弦が水平に伸びるようにするにはどうすればよいですか?
アップデート
Malachiの受け入れられた回答を使用して、Row 1コードをsveltifyすることができました(Row 2は同じままです):
// Create Row 1
var row = new HtmlTableRow();
var cell1 = new HtmlTableCell();
var cell2 = new HtmlTableCell();
row.Cells.Add(cell1);
row.Cells.Add(cell2);
dynamicTable.Rows.Add(row);
// Populate row 1
LiteralControl section1Hdr = new LiteralControl("<h2>Section 1: Platypus Information</h2>");
LiteralControl section2Hdr = new LiteralControl("<h2>Section 2: PoisonToe Information</h2>");
cell1.ColSpan = 4;
cell2.ColSpan = 2;
cell1.Controls.Add(section1Hdr);
cell2.Controls.Add(section2Hdr);