源代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<style type="text/css">
.item
{
margin:10px;
border-bottom:solid 1px #CCC;
}
.item2
{
margin:5px;
}
.input
{
width:200px;
}
</style>
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="item">
請輸入您想要的選項數:
<asp:TextBox runat="server" CssClass="item" ID="txtTextCount" ></asp:TextBox>
<asp:Button runat="server" ID="btnCreate" Text="創建" Width="83px" />
<asp:Button runat="server" ID="btnOK" Text="Get TextBox Content" ValidationGroup="ShowListContent"
onclick="btnOK_Click" />
</div>
<div>
標題:<asp:TextBox ID="TextBox1" runat="server" Height="45px" ReadOnly="True"
Width="325px"></asp:TextBox>
<br />
調查日期:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</div>
<div runat="server" id="divControls" class="item"></div>
<div runat="server" id="divMessage">
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</div>
</form>
</body>
</html>
后台
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
private void CreateTextBoxList(int num)
{
HtmlGenericControl div;
HtmlGenericControl span;
TextBox txt;
TextBox box;
RegularExpressionValidator rev;
for (int i = 0; i < num; i++)
{
//创建div
div = new HtmlGenericControl();
div.TagName = "div";
div.ID = "divTextBox" + i.ToString();
div.Attributes["class"] = "item2";
//创建span
span = new HtmlGenericControl();
span.ID = "spanTextBox" + i.ToString();
span.InnerHtml = "選項" + (i + 1).ToString() + ":";
//创建TextBox
box = new TextBox();
box.ID = "box" + i.ToString();
box.Text = (i+1).ToString();
box.Width=15;
//创建TextBox
txt = new TextBox();
txt.ID = "txt" + i.ToString();
txt.CssClass = "input";
//创建格式验证控件,并且将其关联到对应的TextBox
rev = new RegularExpressionValidator();
rev.ID = "rev" + i.ToString();
rev.ControlToValidate = txt.ID;
rev.Display = ValidatorDisplay.Dynamic;
//添加控件到容器
div.Controls.Add(span);
div.Controls.Add(box);
div.Controls.Add(txt);
div.Controls.Add(rev);
divControls.Controls.Add(div);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
int txtCount = int.Parse(txtTextCount.Text);
// 注意:每次PostBack时,都需要重新动态创建TextBox
CreateTextBoxList(txtCount);
}
}
protected void btnOK_Click(object sender, EventArgs e)
{
TextBox txt;
StringBuilder sbResult = new StringBuilder();
int txtCount = int.Parse(txtTextCount.Text);
//遍历获取动态创建的TextBox们中的Text值
for (int i = 0; i < txtCount; i++)
{
//注意:这里必须通过上层容器来获取动态创建的TextBox,才能获取取ViewState内容
txt = divControls.FindControl("txt" + i.ToString()) as TextBox;
if (txt != null && txt.Text.Trim().Length > 0)
{
sbResult.AppendFormat("選項{0}:<br /><br /><br /> {1}.<br />", i + 1, txt.Text.Trim());
}
}
divMessage.InnerHtml = sbResult.ToString();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
vs2008+sql server 2005 实现的投票系统 (546个子文件)
class_upload.asp 7KB
class_upload.asp 7KB
commands.asp 5KB
upload.asp 3KB
connector.asp 3KB
io.asp 2KB
basexml.asp 2KB
config.asp 2KB
config.asp 2KB
util.asp 1KB
io.asp 836B
result.aspx 6KB
balloting.aspx 6KB
Default.aspx 3KB
Update.aspx 3KB
Show.aspx 2KB
connector.aspx 1KB
upload.aspx 1KB
check.aspx 438B
ResolveAssemblyReference.cache 7KB
ResolveAssemblyReference.cache 5KB
connector.cfm 11KB
spellchecker.cfm 6KB
upload.cfm 6KB
config.cfm 3KB
config.cfm 3KB
connector.cgi 4KB
web.config 8KB
TitleService.cs 10KB
Update.aspx.cs 4KB
Helper.cs 4KB
Default.aspx.cs 3KB
TitleManager.cs 3KB
balloting.aspx.cs 2KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
check.aspx.cs 1KB
Show.aspx.cs 1KB
Title.cs 1KB
Option.cs 1KB
Control.cs 668B
result.aspx.cs 451B
DAL.csproj 3KB
BLL.csproj 3KB
Models.csproj 3KB
DBHelper.csproj 2KB
fck_editor.css 8KB
fck_editor.css 8KB
fck_editor.css 8KB
datepicker.css 3KB
datepicker.css 3KB
datepicker.css 3KB
datepicker.css 3KB
fck_internal.css 2KB
fck_dialog.css 2KB
fck_dialog.css 2KB
fck_dialog.css 2KB
fck_editorarea.css 2KB
browser.css 2KB
fck_dialog_common.css 2KB
fck_showtableborders_gecko.css 1KB
css.css 1KB
css.css 1KB
spellerStyle.css 888B
WdatePicker.css 153B
WdatePicker.css 153B
FreeTextBox.dll 736KB
FredCK.FCKeditorV2.dll 36KB
WebValidates.dll 32KB
DAL.dll 9KB
DAL.dll 9KB
DAL.dll 9KB
DAL.dll 9KB
Models.dll 6KB
Models.dll 6KB
Models.dll 6KB
Models.dll 6KB
Models.dll 6KB
DBHelper.dll 6KB
DBHelper.dll 6KB
DBHelper.dll 6KB
DBHelper.dll 6KB
DBHelper.dll 6KB
BLL.dll 5KB
BLL.dll 5KB
BLL.dll 5KB
Models.dll 5KB
DBHelper.dll 4KB
DAL.dll 4KB
BLL.dll 4KB
fck_strip.gif 9KB
fck_strip.gif 4KB
fck_strip.gif 4KB
logo_fckeditor.gif 2KB
htm.gif 1KB
html.gif 1KB
rdp.gif 1KB
ai.gif 1KB
共 546 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
- zhengbo242013-12-31感觉一般吧,不过拿来学习还行
- tczjq2012-08-16好用~适合初学者学习
- steprefer2014-12-24挺好的代码
- cshan2152013-06-06是用vb做的,我需要的不符啊。。。所以就没用
wangtuwen
- 粉丝: 16
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功