经过debug发现无论勾选几个,chk.Checked始终等于falseCheckBox chk = (CheckBox)Rp.FindControl("chkMsg");这行代码已确定可以找到控件chkMsg请问高手,为什么chk.Checked的值总是false?
foreach (RepeaterItem Rp in this.msgRepeater.Items)
{
CheckBox chk = (CheckBox)Rp.FindControl("chkMsg");
{
if (chk.Checked)
{
Label lbl = (Label)Rp.FindControl("lblMsg");
id = lbl.Text;
cmd.CommandText = "delete from msg where msgID = " + Convert.ToInt32(id);
cmd.ExecuteNonQuery();
} }
}
foreach (RepeaterItem Rp in this.msgRepeater.Items)
{
CheckBox chk = (CheckBox)Rp.FindControl("chkMsg");
{
if (chk.Checked)
{
Label lbl = (Label)Rp.FindControl("lblMsg");
id = lbl.Text;
cmd.CommandText = "delete from msg where msgID = " + Convert.ToInt32(id);
cmd.ExecuteNonQuery();
} }
}
解决方案 »
- 字符串之间的比较问题
- 自动重命名图片,并将地址保存到数据库
- IE7里面是不是不能用js做图片上传预览?
- 怎样在服务器端关闭浏览器窗口
- asp.net运行页面出现在的一个问题!
- 请问类似于Asp中提交一个form的处理,在ASP.NET怎么处理
- 听说asp.net可以实现这个!!!!谁可以给点代码或提示啊?
- 急急急…… 请大家看看1+1=?这个贴,跪求,我都没分了(我真是想知道是怎么回事)
- 如何将aspx页面中通过TextBox控件得到的字符串转换成SQL Server数据库中支持的Money,float类型?
- 常看到这个词 Cutting Edge ,怎么翻译?
- 帮忙看一下这个URL重写规
- 删除按扭 提示对话框 为什么没用
或者不在<form runat=server>里面
<ItemTemplate>
<tr>
<td style="width:160px;">
<%#DataBinder.Eval(Container.DataItem,"userNickName","昵称:{0}") %>
</td>
<td style="width:90%">
<%#DataBinder.Eval(Container.DataItem,"msgDate","留言时间:{0}")%> <asp:Label ID="lblMsgID" Text =<%#DataBinder.Eval(Container.DataItem,"msgID","{0}") %> runat="server"></asp:Label>
</td>
<td>
<asp:CheckBox ID="chkMsg" Visible = "false" runat="server"/>
</td>
</tr>.....</ItemTemplate>应该没问题啊,前面语句用过
if (power > 0)
{
foreach (RepeaterItem Rp in this.msgRepeater.Items)
{
CheckBox chk = (CheckBox)Rp.FindControl("chkMsg");
chk.Visible = true;
}
}都可以使chk.Visible 设为true
我是直接在<ItemTemplate> 里添加的啊
pageload()下面的
if(!ispostback)
{
绑定代码...
}
中
<ItemTemplate>
<tr>
<td style= "width:160px; ">
<%#DataBinder.Eval(Container.DataItem, "userNickName ", "昵称:{0} ") %>
</td>
<td style= "width:90% ">
<%#DataBinder.Eval(Container.DataItem, "msgDate ", "留言时间:{0} ")%> <asp:Label ID= "lblMsgID " Text = <%#DataBinder.Eval(Container.DataItem, "msgID ", "{0} ") %> runat= "server "> </asp:Label>
</td>
<td>
<asp:CheckBox ID= "chkMsg " Visible = "false " runat= "server "/> </td>
</tr> ..... </ItemTemplate> 有一点想不明白,如果visible="false",那么lz是怎么勾选到的
this.msgRepeater.DataBind(); 这一行
或者
msgRepeater.DataBind(); 这一行
然后下断点
再在以下代码的红色行下断点
foreach (RepeaterItem Rp in this.msgRepeater.Items)
{
CheckBox chk = (CheckBox)Rp.FindControl("chkMsg");
{
if (chk.Checked)
{
Label lbl = (Label)Rp.FindControl("lblMsg");
id = lbl.Text;
cmd.CommandText = "delete from msg where msgID = " + Convert.ToInt32(id);
cmd.ExecuteNonQuery();
} }
}
然后你起调试,当你想触发红色行的时候,看一下是否断点执行到了绿色行。
如果执行到了绿色行就会出现你开头说的情况,因为重新做了绑定并且默认所有的复选框都没有被选中
visible就等于true了啊。
改为<asp:CheckBox ID= "chkMsg " Checked="True" runat= "server "/>
然后查找所有的msgRepeater.DataBind(),把它改为如下语句
if(!IsPostback)
{
msgRepeater.DataBind()
}
最后在page_load事件的第一行添加如下代码
foreach (RepeaterItem Rp in this.msgRepeater.Items)
{
CheckBox chk = (CheckBox)Rp.FindControl( "chkMsg ");
}
在红色行设置断点查看chk的值
bool strDrive = false;
try
{
SQLT.SetSQLBeginTrans();
for (int i = 0; i < dlHuanzhe.Items.Count; i++)
{
CheckBox CB = (CheckBox)dlHuanzhe.Items[i].FindControl("chk"); if (CB.Checked)
{
strDrive = true;
//隐藏传递ID用一个datatlist就是Parent一个
string delID = ((HiddenField)dlHuanzhe.Items[i].FindControl("id")).Value;
SQLT.Operate("delete from F_Patient where id=" + delID);
}
}
SQLT.SetSQLCommitTrans();
SQLT.ConClose();
}
catch
{
SQLT.SetSQLRollBack();
MessageBox("00006", null);
SQLT.ConClose();
}
if (!strDrive)//判断选中没有
{
MessageBox("00005", null);
}
else//删除后重新绑定
{
//删除后进行重新取总人数
//this.lblRenNum.Text = CalculateRecord().ToString();
this.BindShowF_Patient();
}作为参考不知道对你有用没有
if(!ispostback)
{
绑定代码...
}
中
否则就是全选不中
中午刚和给别人解决的问题