做一个类似于答题后台,一个题目多个选择!
也就是点击添加答案时.无刷新添加个TEXTBOX...
答案是不限制多少个的!...
然后应该怎么获得上面所有输入的值!
帮帮忙谢谢!!最好有例子!谢谢
ID 题目id
TITLE 选项名称
ID_SY 所属题目id
RIGHT 是否答案 这是数据库....
也就是点击添加答案时.无刷新添加个TEXTBOX...
答案是不限制多少个的!...
然后应该怎么获得上面所有输入的值!
帮帮忙谢谢!!最好有例子!谢谢
ID 题目id
TITLE 选项名称
ID_SY 所属题目id
RIGHT 是否答案 这是数据库....
解决方案 »
- asp.net如何判断用户重复登录
- dropdownlist无法触发事件
- 超难正则,求解!!!!
- 求最优SQL语句
- asp.net 用户控件上有个LinkButton叫 LinkButtonExit,点击 LinkButtonExit触发事件!
- datalist里使用js 控制控件的显示隐藏
- 使用 textbox 及时返回信息
- EF无法读取数据库联合主键的表
- ********用ie打印,表格中的背景为什么在预览时没有了???******
- 想学javascript,提供优秀的电子书籍下载!!(在线给分)
- 错误 31 未能找到文件XXX'存储空间不足,无法完成此操作。 求解.....
- 页面调用ActiveX插件问题
---------------------------------------l 里保存的就是了。
int count = 0;
int.TryParse(hidCount.Value, out count);
for (int i = 0; i < count; i++)
{
l.Add(string.IsNullOrEmpty(Request.Form["txt" + i.ToString()]) ? null : Request.Form["txt" + i.ToString()]);
}
楼主,恭喜你找到答案了.
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="添加TextBox" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="获取TextBox值" />
后台C#:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["no"] = "0";
}
else
{
for (int i = 1; i <= Convert.ToInt16(ViewState["no"]); i++)
{
TextBox tb = new TextBox();
tb.ID = "tb" + i.ToString();
this.Panel1.Controls.Add(tb);
}
}
}
protected void Button1_Click(object sender, EventArgs e)//添加TextBox
{
TextBox tb = new TextBox();
ViewState["no"] = (Convert.ToInt16(ViewState["no"]) + 1).ToString();
tb.ID = "tb" + ViewState["no"].ToString();
this.Panel1.Controls.Add(tb);
}
protected void Button2_Click(object sender, EventArgs e)//获取TextBox中的值
{
for (int i = 1; i <= Convert.ToInt16(ViewState["no"]); i++)
{
string v = (this.Panel1.FindControl("tb" + i.ToString()) as TextBox).Text;
Response.Write(v + "<br />");
}
}
l.Add(Request.Form["txt" + i.ToString()]);
l.Add(Request.Form["txt" + i.ToString()]??"");
不过放在UpdataPanel里也可以达到无刷新的效果!!
我想在TEXTBOX后面加个删除..删除多余的TEXTBOX...应该怎么实现呢?
谢谢
还有一个问题想请教下你!
我想在TEXTBOX后面加个删除..删除多余的TEXTBOX...应该怎么实现呢?
谢谢
但是我添加多了...10个了..
我现在不想要那么多..我要-去5个..我应该怎么实现?
我没有遇到这个问题
因为我提交后.整个过程就完成了.
我不需要TEXTBOX还在了!
这个问题嘛!我帮不了你!
你问下sandy945他吧!
他能帮上你!!
我也是在学习阶段呢!
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>无标题页</title> <script language="javascript" type="text/javascript">
var count=0;
function AddTextBox()
{
var div = document.getElementById('div');
//insertAdjacentHTML 不兼容 FF , 如何兼容可查看 prototype ,jQ 等 js 框架。 在这里 insertAdjacentHTML("beforeEnd" 可使用 div.innerHTML+= 替换
div.insertAdjacentHTML("beforeEnd", "<div id='div" + count + "' ><input type='text' id='txt" + count + "' name='txtName' /> <input type='button' value='删除' onclick='del(" + count + ");' /></div>");
count++;
}
function SetValue()
{
document.getElementById('<%=hidCount.ClientID %>').value=count;
}
function del(id) {
var div = document.getElementById('div');
div.removeChild(document.getElementById('div'+id));
}
</script></head>
<body>
<form id="form1" runat="server">
<div id="div">
</div>
<input type="button" id="btnAdd" value="增加" onclick="AddTextBox()" />
<asp:Button ID="btnSubmit" runat="server" Text="提交" OnClientClick="SetValue()" OnClick="btnSubmit_Click" />
<asp:HiddenField ID="hidCount" runat="server" />
</form>
</body>
</html>protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hidCount.Value = "0";
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{ if (!string.IsNullOrEmpty(Request.Form["txtName"]))
{ int count = 0;
int.TryParse(hidCount.Value, out count); string[] myArray = Request.Form["txtName"].Split(','); StringBuilder sb = new StringBuilder("<script>document.getElementById('div').innerHTML=\"");
for (int i = 0; i < myArray.Length; i++)
{
sb.AppendFormat("<div id='div{0}'><input type='text' id='txt{0}' name='txtName' value='{1}' /> <input type='button' id='btn{0}' value='删除' onclick='del({0});' /></div>", i, myArray[i]);
}
sb.AppendFormat("\";count={0};</script>", hidCount.Value); ClientScript.RegisterStartupScript(GetType(), "AddTextBox", sb.ToString()); }
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>无标题页</title> <script language="javascript" type="text/javascript">
var count = <%= txtCount %>;
function AddTextBox() {
var div = document.getElementById('div'); var html = "<div id='div" + count + "' ><input type='text' id='txt" + count + "' name='txtName' /> <input type='button' value='删除' onclick='del(" + count + ");' /></div>"; //insertAdjacentHTML 不兼容 FF , 如何兼容可查看 prototype ,jQ 等 js 框架。 在这里 insertAdjacentHTML("beforeEnd" 可使用 div.innerHTML+= 替换
div.insertAdjacentHTML("beforeEnd", html);
count++;
}
function SetValue() {
document.getElementById('<%=hidCount.ClientID %>').value = count;
}
function del(id) {
var div = document.getElementById('div');
div.removeChild(document.getElementById('div' + id));
}
</script></head>
<body>
<form id="form1" runat="server">
<div id="div"><%=divContent %>
</div>
<input type="button" id="btnAdd" value="增加" onclick="AddTextBox()" />
<asp:Button ID="btnSubmit" runat="server" Text="提交" OnClientClick="SetValue()" OnClick="btnSubmit_Click" />
<asp:HiddenField ID="hidCount" runat="server" />
</form>
</body>
</html>
protected string divContent, txtCount = "0"; protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hidCount.Value = "0";
}
} protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Request.Form["txtName"] != null)
{ int count = 0;
int.TryParse(hidCount.Value, out count); string[] myArray = Request.Form["txtName"].Split(','); StringBuilder sb = new StringBuilder(); for (int i = 0; i < myArray.Length; i++)
{
sb.AppendFormat("<div id='div{0}'><input type='text' id='txt{0}' name='txtName' value='{1}' /> <input type='button' id='btn{0}' value='删除' onclick='del({0});' /></div>", i, myArray[i]);
} divContent = sb.ToString(); txtCount = hidCount.Value;
}
}