日期:2014-05-18  浏览次数:20454 次

如何选中CheckBox就将其值写到TextBox中?
如题,有很多的CheckBox,当选中其中一个或几个时要将CheckBox的值写到TextBox中,并且值之间要用逗号或分号隔开(因为要写到数据库的一个字段里面)。

还需要当CheckBox的勾去掉时TextBox中对应的值也消失?

上述要如何做到?

请各位高手指点一下,谢谢!

------解决方案--------------------
修改了一下, 去掉了最后一个逗号, 你参考一下:
HTML code

<%@ 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" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;<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>