我用以个checkboxlist绑定数据,然后去判断是否被选中!结果我在页面选中了,但是在代码里checked还是false!
为什么啊?
前台:
<div style="font-size:15px;">
    <div style="width:600px; background-color:#b1edd7; text-align:center">发文管理</div>
    <table width="600px">
        <tr>
            <td style="width: 100px">主题<asp:Label ID="lbl" runat="server" ForeColor="red" Text="*"></asp:Label></td>
            <td style="width: 250px; text-align:left"><asp:TextBox ID="txttitle" runat="server" Width="250px" ></asp:TextBox></td>
            <td style="width: 140px; text-align:right">时间</td>
            <td style="width: 110px; text-align:left"><asp:TextBox ID="txttime" runat="server" Width="100px" onfocus="setday(this);"></asp:TextBox></td>
        </tr>
        <tr>
            <td style="width:100px;">收件人</td>
            <td colspan="3" style="text-align:left">
                <div style="width:100%">
                    <asp:CheckBoxList ID="cklist" runat="server" RepeatColumns="5" RepeatDirection="Horizontal"></asp:CheckBoxList>
                </div>
                <input id="chkall" type="checkbox" onclick="CheckAll(this);"/>全选
            </td>
        </tr>
        <tr>
            <td style="width: 100px">附件</td>
            <td colspan="3" style="text-align:left"><a href="FileUpload.htm">添加附件</a></td>
        </tr>
        <tr>
            <td style="vertical-align:middle; width: 100px;">正文<asp:Label ID="lblx" runat="server" Text="*" ForeColor="red"></asp:Label></td>
            <td colspan="3" style="text-align:left">
                <asp:TextBox ID="txtcontent" runat="server" TextMode="MultiLine" Width="500px" Height="150px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td style="width: 100px">重要程度</td>
            <td colspan="3" style="text-align:left"><asp:DropDownList ID="ddlsta" runat="server">
                <asp:ListItem Text="一般" Value="0"></asp:ListItem>
                <asp:ListItem Text="重要" Value="1"></asp:ListItem>
                <asp:ListItem Text="紧急" Value="2"></asp:ListItem>
            </asp:DropDownList></td>
        </tr>
        <tr>
            <td colspan="4" style="text-align:center"><asp:Button ID="btnSave" runat="server" Text="确定" OnClick="btnSave_Click" /></td>
        </tr>
    </table>
</div>然后再这里获取
protected string GetRecipient()
    {
        string Recipient = "";
        if (cklist.Items.Count > 0)
        {
            for (int i = 0; i < cklist.Items.Count; i++)
            {
                if (cklist.Items[i].Selected == true)       //这里的Selected永远为false,选中了也还是false
                    Recipient += cklist.Items[i].Text + ",";
            }
        }
        return Recipient;
    }

解决方案 »

  1.   

    你在js中设置的选中在cs 中获取不到
      

  2.   

    绑定的代码放到这里面去
            if (!IsPostBack)
            {
                //绑定checkboxlist
            }
      

  3.   

    1,绑定函数没放在if (!IsPostBack)内
    2,command 事件设置了绑定并且没判断commandname 
      

  4.   

    建议在jsCheckAll(this)中
    把选中的cklist.Items[i].Text 保存在隐藏域中<input type="hidden"
      

  5.   

     protected void Page_Load(object sender, EventArgs e)
        {
            RecipientBind();
        }
      

  6.   

    不是js问题,我前一个页面也是用的这个js方法。没问题!我单个选中后台也不行!奇怪的很呐!
      

  7.   

    你这哪里放了?
    if (!IsPostBack) 

        RecipientBind();
    }