我用以个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;
}
为什么啊?
前台:
<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;
}
解决方案 »
- 关于FCKeditor,在本地开发时,在本地没找到上传图片,向高手求救啊!!!
- 在线急等,当选中checkbox时dropdownlist才生效
- 用javascript对用户界面效验的问题。
- 如何判断GridView自动删除的是哪条记录?
- 高分求企业进销存代码(ASP.NET/MS SQLSERVER)
- 各位前辈救命啊!.NET中使用FTP上传大文件的问题
- “图片变幻显示控件”发布 + 今天再散200分,BS所有问问题给10分、20分的和小日本
- 如何确定数组中的标号位置?
- 求connection链接数据库的类源码(vb.net)
- Asp.net中控件gridview 如何将数据横向显示
- 纠结老的小问题
- 打开网页自动的输入账号密码并显示网页
if (!IsPostBack)
{
//绑定checkboxlist
}
2,command 事件设置了绑定并且没判断commandname
把选中的cklist.Items[i].Text 保存在隐藏域中<input type="hidden"
{
RecipientBind();
}
if (!IsPostBack)
{
RecipientBind();
}