日期:2014-05-17 浏览次数:20445 次
<asp:Panel ID="Panel1" runat="server" Width="105px"> </asp:Panel> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
string a = ",序号,车号,姓名,联系方式"; string[] s = a.Split(new string[1] { "," }, System.StringSplitOptions.None); for (int i = 1; i <= 3; i++) { TextBox txt = new TextBox(); txt.ID = "TextBox" + i.ToString(); //txt.top = i * 20; Panel1.Controls.Add(txt); ((Label)this.FindControl("label" + i)).Text = s[i]; }
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><input name="TextBox1" type="text" id="TextBox1" /><br> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><input name="TextBox2" type="text" id="TextBox1" /><br> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label><input name="TextBox3" type="text" id="TextBox1" /><br>
string a = ",序号,车号,姓名,联系方式"; string[] s = a.Split(new string[1] { "," }, System.StringSplitOptions.None); for (int i = 1; i <= 3; i++) { Label lb = new Label(); lb.ID = "Label" + i.ToString(); TextBox txt = new TextBox(); txt.ID = "TextBox" + i.ToString(); lb.Text = "<br />"+s[i]; Panel1.Controls.Add(lb); Panel1.Controls.Add(txt); }
------解决方案--------------------
通过后台编程的方式可以直接实现。
以下为前台
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
------解决方案--------------------
另外,不建议使用后台编程方式实现,除非前台结构不确定。
------解决方案--------------------
怎么感觉拉的比你生产的快吧。。
要不做个表把TextBox放repeater里面绑定上。。。
------解决方案--------------------
string a = ",序号,车号,姓名,联系方式";
string[] s = a.Split(new string[1] { "," }, System.StringSplitOptions.None);
for (int i = 1; i <= 3; i++) {
TextBox txt = new TextBox();
txt.ID = "TextBox" + i.ToString(); //txt.top = i * 20;
Label la = new Label();
la.Text = s[i];
Panel1.Controls.Add(la);
Panel1.Controls.Add(txt);
Panel1.Controls.Add(new HtmlGenericControl("br"));
}
------解决方案--------------------