asp.net table控件动态生成表格操作实例(代码调试通过)
.aspx
<form id="form1" method="post" runat="server">
<asp:label id="label1" runat="server">asp.net table控件动态生成表格操作实例</asp:label>
<asp:button id="button1" runat="server"
text="生 成"></asp:button>
<asp:table id="table1" runat="server"
gridlines="both"></asp:table>
<asp:dropdownlist id="dropdownlist2"
runat="server">
<asp:listitem value="1">1列</asp:listitem>
<asp:listitem value="2">2列</asp:listitem>
<asp:listitem value="3">3列</asp:listitem>
<asp:listitem value="4">4列</asp:listitem>
<asp:listitem value="5">5列</asp:listitem>
</asp:dropdownlist>
<asp:dropdownlist id="dropdownlist1"
runat="server">
<asp:listitem value="1">1行</asp:listitem>
<asp:listitem value="2">2行</asp:listitem>
<asp:listitem value="3">3行</asp:listitem>
<asp:listitem value="4">4行</asp:listitem>
<asp:listitem value="5">5行</asp:listitem>
</asp:dropdownlist>
</form>
.aspx.cs
private void button1_click(object sender, system.eventargs e)
{
int numrows;
int numcells;
int i=0;
int j=0;
int row=0;
tablerow r;
tablecell c;
//产生表格
numrows=convert.toint32(dropdownlist1.selectedvalue);
numcells=convert.toint32(dropdownlist2.selectedvalue);
for(i=0;i<numrows;i++)
{
r=new tablerow();
if(row/2!=0)
{
r.bordercolor=color.red;
}
row+=1;
for(j=0;j<numcells;j++)
{
c=new tablecell();
c.controls.add(new literalcontrol
("row"+j+",cell"+i));
r.cells.add(c);
}
table1.rows.add(r);
}
}
新闻热点
疑难解答
图片精选