关于gridview的超级怪问题
前台代码:
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID= "celected " runat= "server " > </asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:Button ID= "btnhy " runat= "server " Text= "还原 " CssClass= "button " OnClick= "btnhy_Click "/>
后台代码:
protected void btnhy_Click(object sender, EventArgs e)
{
bool isdelete = false;
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
bool isChecked = ((CheckBox)GridView1.Rows[i].FindControl( "celected ")).Checked;
string strId = GridView1.DataKeys[i].Values[0].ToString();
if (isChecked)
{
isdelete = true;
string sql = "update t_message set deleteid=0 where id= " + strId + " ";
obj.New();
obj.execnonsql(sql);
obj.Close();
}
}
if (isdelete == true)
{
mainlr.Text = " <font color=red> 操作成功! </font> ";//输出错误信息
dgdbind();
}
else
{
Response.Write( " <script type= 'text/javascript ' > alert( '请先选择记录! '); </script> ");
}
}
各位:帮帮忙。
这是一个关于gridview的问题,在点击还原按钮的时候,老提示请先选择记录,我明明勾选了复选框的,但就是提示没有选中记录,为什么,请帮忙看哈代码,感谢。
------解决方案--------------------