我想动态添加一个表格,用dropdownlist中的数值控制他的大小,并在指定的地方加入textbook控件。
参考下列代码。
<asp:Table id="Table1" runat="server" BorderWidth="1px" Width="158px" CellPadding="0" CellSpacing="0"></asp:Table>
/// <summary>
/// 输出菜单
/// </summary>
private void showMenue()
{
DataSet ds = connE.GetDs("father","select * from menues where parentId=1 and state=1 order by id");
DataView dv = ds.Tables["father"].DefaultView;
int i=0;
foreach( DataRowView dvR in dv)
{
//一级菜单
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Text=dvR["name"].ToString();
tc.CssClass="title1";
tc.Attributes["onclick"]="showsubmenu("+i+")";
tc.Width=158;
tc.Height=25;
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
//二级菜单
TableRow tr2 = new TableRow();
TableCell tc2 = new TableCell();
tc2.ID="submenu"+i;
tc2.Attributes["style"]="disply:none";
Table tbChild = new Table();
tbChild.CssClass="title2";
tbChild.Attributes["width"]="100%";
DataSet dsChild;
string strSql="select * from menues where parentId="+dvR["id"]+" and state=1";
dsChild = connE.GetDs("child",strSql);
DataView dvChild = dsChild.Tables["child"].DefaultView;
foreach ( DataRowView dvRChild in dvChild)
{
TableRow trChild = new TableRow();
TableCell tcChild = new TableCell();
tcChild.Attributes["align"]="Center";
HyperLink hl = new HyperLink();
hl.Text=dvRChild["name"].ToString();
hl.NavigateUrl=dvRChild["url"].ToString();
hl.Target="main";
tcChild.Controls.Add(hl);
trChild.Cells.Add(tcChild);
tbChild.Rows.Add(trChild);
}
tc2.Controls.Add(tbChild);
tr2.Cells.Add(tc2);
Table1.Rows.Add(tr2);
//dsChild.Tables.Clear();
i++;
}
}