<asp:GridView ID="gvFun" runat="server"
GridLines="None" AutoGenerateColumns="False" DataKeyNames="f_Id,f_Name">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkFun" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView> private void AdFunDelete()
{
try
{
for (int i = 0; i < this.gvFun.Rows.Count; i++)
{
CheckBox cbFun = (CheckBox)this.gvFun.Rows[i].FindControl("chkFun");
if (cbFun.Checked == true) //error
{
。
}
}
}
catch
{
}
}
在error处总是返回false,但是CheckBox已经选中了,请问是什么问题?
GridLines="None" AutoGenerateColumns="False" DataKeyNames="f_Id,f_Name">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkFun" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView> private void AdFunDelete()
{
try
{
for (int i = 0; i < this.gvFun.Rows.Count; i++)
{
CheckBox cbFun = (CheckBox)this.gvFun.Rows[i].FindControl("chkFun");
if (cbFun.Checked == true) //error
{
。
}
}
}
catch
{
}
}
在error处总是返回false,但是CheckBox已经选中了,请问是什么问题?
要不就是这个返回值为false,有没有NAME=chkFun的控件啊
就可以了。
{
//对有没有选中进行判断直接按删除按钮则报错
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 dbo.F_User where userid='" + delID + "'");
}
} SQLT.SetSQLCommitTrans();
SQLT.ConClose();
}
catch
{
SQLT.SetSQLRollBack();
Response.Write("<script>alert('删除失败。')</script>");
SQLT.ConClose();
}
if (!strDrive)//判断选中没有
{
Response.Write("<script>alert('请选择要删除的数据。')</script>");
}
else//删除后重新绑定
{
this.BindShowF_Patient(); }
}
if(!this.IsPostback)
{
Bind();
}
里的。
肯定没有重新绑定阿
private void dataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
this.dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
如果问题得到解决的话,hoho...,分拿来!