如题,有很多的CheckBox,当选中其中一个或几个时要将CheckBox的值写到TextBox中,并且值之间要用逗号或分号隔开(因为要写到数据库的一个字段里面)。还需要当CheckBox的勾去掉时TextBox中对应的值也消失?上述要如何做到?请各位高手指点一下,谢谢!
解决方案 »
- 动态添加一个联动控件该怎么写???
- 为什么我无法把fileupload控件里的地址存进数据库
- 如何获取.flv文件的总的播放时间
- 传值问题没说清楚,在散 40分!!!!
- .net中类似vb中的mid函数
- 小弟想学。net,大虾们指点一下教材
- 关于隐藏路径images.aspx?id=8564098.jpg如何实现
- 验证控件让按钮无效,aspnetregiis -i,-c都没用,程序只能在服务器端运行,客户端按钮无效,怎么办啊?
- 怎样才能做到像QQ那样的聊天实时性
- 两个问题,请高手指点.
- 页面上的事件又不能执行了 ??/ 求救```````````````
- 散分求救!!关于批量读取文件的问题!!!
lz留个邮箱,明天发给你
另外,保存CheckBoxList的选择值,是不用先保存在TextBox之后,再存的.
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Height="235px" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged"
Width="322px" AutoPostBack="True">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
int len = CheckBoxList1.Items.Count;
string str = string.Empty;
for (int i = 0; i < len; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
str += CheckBoxList1.Items[i].Value.ToString() + ",";
}
TextBox1.Text = str;
}
}
}
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Height="235px" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged"
Width="322px" AutoPostBack="True">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
int len = CheckBoxList1.Items.Count;
string str = string.Empty;
for (int i = 0; i < len; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
str += CheckBoxList1.Items[i].Value.ToString() + ",";
}
} if (str.Length == 0)
{
TextBox1.Text = "";
}
else
{
if (str.Substring(str.Length - 1, 1) == ",")
{
TextBox1.Text = str.Substring(0, str.Length - 1);
}
}
}
}希望对你有帮助