日期:2014-05-18  浏览次数:20444 次

我是新手,写的一个多条记录删除的删除事件
删除按钮是与DataGrid分开的下面是删除按钮事件:

private   void   QKdelete_Click(object   sender,   System.EventArgs   e)
{
        for(int   i=1;i <=WGQKnum();i++)//WGQKnum()是DataGrid的记录个数
        {
if(((CheckBox)WGQK.Items[i].Cells[1].FindControl( "BHQK ")).Checked==true)
        {
                QKdelete.Attributes[ "onClick "]= "alert(1) ";
        }
        }
}
但是在运行到:
if(((CheckBox)WGQK.Items[i].Cells[1].FindControl( "BHQK ")).Checked==true)
的时候就无法运行,提示的错误为:

未将对象引用设置到对象的实例。  

我就是想判断被选中的复选框是否被选中,选中之后得到那个复选框的值,然后连接数据库删除...

前台的DataGrid中的复选框我是用 <input   value= ' <%#DataBinder.Eval(...)%> '/>


代码:


<asp:datagrid   id= "WGQK "   style= "Z-INDEX:   157;   LEFT:   128px;   POSITION:   absolute;   TOP:   80px "   runat= "server "
Width= "1000px "   AutoGenerateColumns= "False ">
<Columns>
<asp:TemplateColumn   HeaderText= "选择 ">
<HeaderStyle   HorizontalAlign= "Center "   Width= "40px "   VerticalAlign= "Middle "   Font-Bold= "True "> </HeaderStyle>
<ItemStyle   HorizontalAlign= "Center "   VerticalAlign= "Middle "> </ItemStyle>
<ItemTemplate>
<span   style= "TEXT-ALIGN:   center "> <input   type=checkbox   id= "BHQK "   value= ' <%#DataBinder.Eval(Container.DataItem, "编号 ")%> '>
</span>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn   HeaderText= "检查时间 ">
<HeaderStyle   HorizontalAlign= "Center "   Width= "80px "   VerticalAlign= "Middle "   Font-Bold= "True "> </HeaderStyle>
<ItemStyle   HorizontalAlign= "Center "   VerticalAlign= "Middle "> </ItemStyle>
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "检查时间 ")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn   HeaderText= "检查内容 ">
<HeaderStyle   HorizontalAlign= "Center "   Width= "100px "   VerticalAlign= "Middle "   Font-Bold= "True "> </HeaderStyle>
<ItemStyle   HorizontalAlign= "Center "   VerticalAlign= "Middle "> </ItemStyle>
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "检查内容 ")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn   HeaderText= "检查情况 ">
<HeaderStyle   HorizontalAlign= "Center "   Width= "100px "   VerticalAlign= "Middle "   Font-Bold= "True "> </HeaderStyle>
<ItemStyle   HorizontalAlign= "Center "   VerticalAlign= "Middle "> </ItemStyle&g