在CheckBox中加载事件,可以用Javascript写
循环只要找到一个CheckBox打勾,就Enable 按钮,否则Disable传递参数可以用隐藏的控件解决

解决方案 »

  1.   

    DataGrid说明 
    本文所有举例都将使用以下DataGrid: 
    <asp:DataGrid id="dg" runat="server" 
    Bordercolor="black" 
    gridlines="vertical" 
    font-names="Arial" 
    font-size="10pt" 
    HeaderStyle-BackColor="#FFCC00" 
    ItemStyle-BackColor="#FFCC66" 
    AlternatingItemStyle-BackColor="#FFFFFF" 
    AutoGenerateColumns="False"> 
     
    <Columns> 
     
    </Columns> 
    </asp:datagrid> 
    以上DataGrid并不能直接使用,我们需要和具体应用结合。在这里,我们主要目的是知道这个DataGrid的一些具体设置情况。 
     
    TemplateColumn 
    我们知道,有很多方法可以显示一些特殊的数据列,比如使用boundcolumns, hyperlinkcolumns等。然而,使用TemplateColumn可以帮助我们实现更多功能,看以下几个举例: 
    CheckBox / CheckBoxList 
    CheckBox可以被用于选择一个数据(事情)的状态是真、假等,由于其很直观的使用“勾”和“叉”来表示真、假,所以,往往比一个简单的“Yes”和“No”更加受欢迎。在DataGrid中,我们可以使用CheckBox来实现很好的数据删除功能,首先,我们让访问者选择需要删除的数据,然后在DataGrid的底部提供一个数据删除提交按钮,这样的删除功能用户比较不容易出错。来看一个举例: 
    <asp:templatecolumn> 
    <itemtemplate> 
    <asp:checkbox runat="server" Checked='<%# Container.DataItem("Married") %>' Enabled="False" id="chk1" /> 
    </itemtemplate> 
    </asp:templatecolumn> 
    程序执行效果如下: 
     
     
    以上程序中,CheckBox用于显示数据字段Married,如果该数据字段为真,CheckBox为勾;如果为假,CheckBox为叉。我们发现,使用CheckBox来表现数据字段的真假很直观。 
    RadioButton / RadioButtonList 
    RadioButton的使用,我们可以参考以下代码: 
    <asp:templatecolumn> 
    <edittemplate> 
    <asp:radiobuttonList runat="server"> 
    <asp:listitem value="Trek">Star Trek</asp:listitem> 
    <asp:Listitem value="Wars">Star Wars</asp:listitem> 
    </asp:radiobuttonlist> 
    </edittemplate> 
    </asp:templatecolumn> 
    程序执行效果如下: 
     
     
    什么时候使用TemplateColumns 
    本文所有举例都使用templatecolumn来显示数据。尽管不是所有数据显示都是使用templatecolumn,但是,当我们需要对DataGrid具有较多控制的时候,就必须使用它。比如, 
    HyperLink column只许显示一列数据,当我们需要显示更多的时候,就必须使用templatecolumn了,代码如下: 
    <asp:templatecolumn> 
    <itemtemplate> 
    <a href=../view.aspx?id=<%# Container.DataItem("ID") %>><%# Container.DataItem("ID") & Container.DataItem("Name") %></a> </itemtemplate>  
    </asp:templatecolumn>
      

  2.   

    数据验证 
    程序的严谨最起码也是最常见的就是提交前的数据验证,在DataGrid中使用Web Forms也有这个要求: 
    <asp:templatecolumn> 
    <itemtemplate> 
    <%# Container.DataItem("Age") %> 
    </itemtemplate> 
    <edititemtemplate> 
    <asp:RegularExpressionValidator runat="server" ControlToValidate="txtAge" ErrorMessage="Invalid input for Age" 
    ValidationExpression="[0-9]{2}" /><br> 
    <asp:textbox runat="server" id="txtAge" value='<%# Container.DataItem("Age") %>' /> 
    </edititemtemplate> 
    </asp:templatecolumn> 
    以上代码要求输入的年龄字段(Age)只能为两位的数字,我们来看执行效果: 
     
     
    上图我们看到,不能通过验证数据将不被提交。 
     
    总结 
    Web Forms在DataGrid中的使用能简化程序界面的复杂程度,提高程序可用性。但是,如果使用不当,反而会增加程序执行时间,占用系统资源。所以,使用的时候,我们应该根据程序特点采用适当方式。
      

  3.   

    谢谢你的帮助 
    http://www.detech.com.cn/labv20/bank/bank_confirm.asp
    这个就是所需要实现功能的界面
    但是我需要用c#编写 能说详细点吗?谢谢了:)
      

  4.   

    给你代码:
    private void tb_delete_Click(object sender, System.EventArgs e)
    {
    module.WantInfolog.WantInfologDetail cs_br=new module.WantInfolog.WantInfologDetail();
    string sql="";
    string id;
    bool checkeds=false;
    foreach(DataGridItem dgi in DataGrid1.Items)
    {

    CheckBox cb=(CheckBox)(dgi.Cells[0].Controls[1]);
    if (cb.Checked==true)
    {
    int d= dgi.ItemIndex;
    id = DataGrid1.DataKeys[d].ToString();
    sql+=id+",";
    checkeds=true;
    module.WantInfolog.WantInfologDetail cs_wantlog=new module.WantInfolog.WantInfologDetail(Convert.ToInt32(id));
    module.publicsub pub=new module.publicsub();
    string jobid=cs_wantlog.get_WantInfoid;
    string userid=cs_wantlog.get_PersonalInfoid;
    string compid=Session["id"].ToString();
    Response.Write(pub.popupWindowsMax("test/hjemail.asp?compid="+compid+"&jobid="+jobid+"&userid="+userid));
    cs_wantlog=null;
    }
    }
    if(checkeds)
    {
    int sqllength=sql.Length;
    if(sql.Substring(sqllength-1,1).Equals(","))
    cs_br.SB_update_info(sql.Substring(0,sql.Length-1));
    else
    cs_br.SB_update_info(sql);
    Response.Write("<script language=javascript>alert('您选择的人员已成功放入垃圾桶!');window.location='WantInfoManager.aspx';</script>");

    }
    else
    Response.Write("<script language=javascript>alert('您没有选择任何人员!');</script>");
    }
      

  5.   

    System.Web.UI.WebControls.CheckBox CB= (CheckBox)this.DataGrid1.Rows[i].Cells
                              [j].FindControls("CheckBox1");
    注意:由于作用域的关系CB应声明为全局。在CheckBox1 的CheckedChanged事件中
    this.button1.Visible=true;
      

  6.   

    或者在CB 的CheckedChanged事件中
    this.button1.Visible=true;
    自己测试
      

  7.   

    进去了,但是他那个应该不是用C#写的吧,我写了一个,但是每点一次CHECKBOX会刷新一次这个是把autopostback打开的后果,但是只能这样,可以实现选中的记录删除
      

  8.   

    在模版列中加入一控件,将它和要记录的ID绑定,然后用循环筛选CHACKBOX为TRUE的删除就行,具体代码上面有人写了,你参考参考就行
      

  9.   

    删除了checkbox选中的项,那我怎么把checkbox选中的进行了审批操作后的项提交数据库呢?
      

  10.   

    晕倒哦,一个道理,把要审批的记录做个标记就行了(估计你的审批就是在审批字段中做个标记,然后刷新一下DATAGRDI查找未审批的记录)不需要删除的