我想在checkbox中勾选之后,可以实现删除,编辑。并且在grid header上面同样有个check box勾选之后呢,下面的Item的checkbox可以全选。由哪位大侠能给我提供代码呢。好着急啊。

解决方案 »

  1.   

    function CheckAll(check)
    {
    for (var i=0;i<document.all.length;i++)
    {
    if (document.all(i).CheckItem=="true")
    {
    document.all(i).checked=check.checked;
    }
    }
    }
      

  2.   

    页面
    asp:TemplateColumn>
    <HeaderTemplate>
    <INPUT id="checkAll" onclick="CheckAll(this);" type="checkbox" CHECKED>
    </HeaderTemplate>
    <ItemTemplate>
    <INPUT id="checkOnly" type="checkbox" runat="server" CheckItem="true">
    </ItemTemplate>
      

  3.   

    用javascript来控制吧,遍历datagrid中的所有checkbox控件看是否选中,或设置checkbox的check=true;
      

  4.   

    <script>
    function chkSelect_OnClick(tableRow, checkBox, rowIndex)
    {
    var bgColor;
    if(rowIndex%2 == 0)
    bgColor = "#ffffff";
    else
    bgColor = "#f5f5f5";

        if(checkBox.checked == true)
        tableRow.style.backgroundColor = "#b0c4de";
        else
        tableRow.style.backgroundColor = bgColor;
        
    }
    function chkSelectAll_OnClick(checkBox, regExp)
    {
    re = new RegExp(regExp)
    for(i = 0; i < document.forms[0].elements.length; i++) 
    {
    elm = document.forms[0].elements[i]
    if (elm.type == 'checkbox') 
    {
    if (re.test(elm.id)) 
    {    
        elm.checked = checkBox.checked;
        var tableId = elm.parentNode.parentNode.id;
        var rowIndex = tableId.substring(tableId.length - 1, tableId.length);
        chkSelect_OnClick(document.getElementById(tableId), elm, rowIndex);

    }
    }
    }
    }
    </script>
    <asp:GridView ID="GridView3" Width="100%" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" AllowPaging="True" PageSize="20" OnRowDataBound="GridView3_RowDataBound" EmptyDataText="<br/><font color='#ff0000'>请从左侧列表选择销售客户.</font>" >
                                <Columns>
                                <asp:TemplateField>
                                        <HeaderTemplate>
                                           <asp:CheckBox id="chkSelectedAll" Runat="server"  AutoPostBack="False"></asp:CheckBox>
                                         </HeaderTemplate>
                                         <ItemTemplate>
                                           <asp:CheckBox id="chkSelected"  runat="server"></asp:CheckBox>
                                         </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField  ItemStyle-Width="20px"/>
                                    <asp:BoundField DataField="Code"  ItemStyle-HorizontalAlign="Center"  HeaderStyle-HorizontalAlign="Center" HeaderText="客户编码" SortExpression="Code" />
                                    <asp:BoundField DataField="Name" HeaderText="客户名称" SortExpression="Name" />
                                    
                                </Columns>
                            </asp:GridView>
      

  5.   

    protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                GridViewRow row = e.Row;            if (row.RowType == DataControlRowType.Header)
                {
                    object checkBox = row.FindControl("chkSelectedAll");
                    if (checkBox != null)
                        ((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelectAll_OnClick(" + ((CheckBox)checkBox).ClientID + ", '_chkSelected$')");
                }
                else if (row.RowType == DataControlRowType.DataRow)
                {
                    
                    // Add attributes to the <td>.
                    string tableRowId = GridView3.ClientID + "_row" + row.RowIndex.ToString();
                    row.Attributes.Add("id", tableRowId);
                    object checkBox = row.FindControl("chkSelected");
                    if (checkBox != null)
                    {
                        string clientId = ((CheckBox)checkBox).ClientID;
                        
                        ((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelect_OnClick(" + tableRowId + "," + clientId + "," + row.RowIndex + ")");
                    }
                }
            }
      

  6.   

    #region deldte
    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnDel_Click(object sender, System.EventArgs e)

    int flag=0;
    int result=0;
    for(int  i =0 ; i < gridTrainPlan.Items.Count; i ++)
    {
    CheckBox ListCheck = (CheckBox)gridTrainPlan.Items[i].FindControl("chkSelect");
    Label LabelPK_ID = (Label)gridTrainPlan.Items[i].FindControl("PlanID");
    try
    {
    if(ListCheck.Checked == true)
    {
    flag = 1;
    this.suddenplaniner=SuddenPlanInner2.GetByKey(int.Parse(LabelPK_ID.Text.ToString()));
    this.suddenplaniner.Delete();
    result=1;
    }
    }
    catch(Exception ex) 
    {
    base.MsgBox(ex.Message);
    return;
    }

    }
    if (flag == 0) 
    {
    base.MsgBox("请先选择要进行操作的项!","SuddenPlanInner2List.aspx");
    return;
    }
    if (result!=0) 

    base.MsgBox("删除成功","SuddenPlanInner2List.aspx");
    return;  
    }
    else
    {
    base.MsgBox("删除失败");
    return;
    }
    }
    #endregion
      

  7.   

    怎么现在的女人是多长两只眼睛还是多长两条腿?只TMD恶心。
      

  8.   

    现在的某些男人也真TMD犯贱,看见个女人就跟见了爹似的,也不管它是猪头还是人妖,真TMD饥渴。母猪也有个洞,饥渴得不行就搂着母猪睡去。
      

  9.   

    <HTML>
    <HEAD>
    <title>searchwagemessage</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <LINK href="../../images/style.css" type="text/css" rel="stylesheet">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <SCRIPT language="javascript" src="js\popup.js"></SCRIPT>
    <script language="javascript">
    function chkstr()

    if(document.all.TextBox2.value=='')
    {
     document.all.TextBox2.focus();
     alert('上限查询时间不能为空!');
     return false;
     }
     else if(document.all.TextBox3.value=='')
    {
     document.all.TextBox3.focus();
     alert('下限查询时间不能为空!');
     return false;
     }
     else if(document.all.TextBox1.value=='')
    {
     document.all.TextBox1.focus();
     alert('请输入查询条件!');
     return false;
     }
     }
    </script>
    <script language="javascript">
    function myCheck()
                  {
        var mycount = 0 ;
    var mm = document.getElementsByTagName("input").length ;
    for(var i=0;i<mm;i++)
    {
    var dd = document.getElementsByTagName("input").item(i);
    if(dd.type == "checkbox")
    {
    if(dd.checked == true)
    {
    mycount += 1;
    }
    }
    }if(mycount == 0)
    {
    alert("您还未选择,请选择!");
    return(false);
    }
    else
    {
    return(confirm("本次操作将删除该时间段的所有记录,注意!是该时间段!您真的要删除它吗?"));
    }
    }
    </script>
    <script language="javascript">
    <!--
    function CheckAllCus()
    {     
    for (var k=0;k<document.Form1.elements.length;k++)
    {
    var e = document.Form1.elements[k];
    if (e.id!= 'checkAccept')
     
    e.checked = document.Form1.checkAccept.checked;
    }
    }
    //-->
    </script>
    <script language="JavaScript">
    javascript:window.history.forward(1);
    </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <TABLE id="Table2" style="Z-INDEX: 104; LEFT: 24px; WIDTH: 603px; POSITION: absolute; TOP: 120px; HEIGHT: 168px"
    cellSpacing="1" cellPadding="1" width="603" border="1">
    <TR>
    <TD style="HEIGHT: 11px" align="center" bgColor="#0099cc"><FONT face="宋体"><FONT face="宋体"><STRONG><FONT face="宋体"><FONT face="宋体" color="#ff0033"><STRONG>员工工资查询</STRONG></FONT></FONT></STRONG></FONT></FONT></TD>
    </TR>
    <TR>
    <TD style="HEIGHT: 106px" align="center" colSpan="1" rowSpan="1"><asp:label id="Label2" runat="server" Font-Size="10" ForeColor="#400040">从</asp:label><asp:textbox id="TextBox2" runat="server" Width="80px" ReadOnly="True"></asp:textbox><A onclick="fPopUpDlg('js/date.htm', document.forms[0].TextBox2, 'winpop',300,100, 234, 261);return false"
    href="#"><IMG src="js\datetime.gif" border="0"></A>
    <asp:label id="Label3" runat="server" Font-Size="10" ForeColor="#400040">到 </asp:label><asp:textbox id="TextBox3" runat="server" Width="80px" ReadOnly="True"></asp:textbox><A onclick="fPopUpDlg('js/date.htm', document.forms[0].TextBox3, 'winpop',300,100, 234, 261);return false"
    href="#"><IMG src="js\datetime.gif" border="0"></A>
    <asp:label id="Label1" runat="server" Font-Size="10" ForeColor="#400040">员工编号</asp:label><asp:textbox id="TextBox1" runat="server" Width="84px"></asp:textbox><asp:button id="Button1" runat="server" Text="执行查询"></asp:button>
    <DIV style="OVERFLOW: auto; WIDTH: 594px; HEIGHT: 150px"><asp:datagrid id="DataGrid1" runat="server" Width="673px" HorizontalAlign="Center" ToolTip="双击查看详细信息"
    DataKeyField="ygid" CellPadding="3" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CCCCCC" AutoGenerateColumns="False">
    <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle>
    <ItemStyle Font-Size="12px" ForeColor="#000066"></ItemStyle>
    <HeaderStyle Font-Size="12px" Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="#006699"></HeaderStyle>
    <FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
    <Columns>
    <asp:TemplateColumn>
    <HeaderStyle Width="3%"></HeaderStyle>
    <HeaderTemplate>
    <INPUT id="checkAccept" type="checkbox" onclick="CheckAllCus()">
    <asp:Label id="Label4" runat="server">全选</asp:Label>
    </HeaderTemplate>
    <ItemTemplate>
    <asp:CheckBox id="CB" runat="server"></asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="ygid" HeaderText="员工编号">
    <HeaderStyle Font-Size="10pt" Width="5%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="dixin" HeaderText="底薪/元">
    <HeaderStyle Font-Size="10pt" Width="5%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="jlwage" HeaderText="奖金/元">
    <HeaderStyle Width="5%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="chengfwage" HeaderText="惩罚金/元">
    <HeaderStyle Width="5%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="sfwage" HeaderText="实发工资/元">
    <HeaderStyle Font-Size="10pt" Width="5%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="wagedate" HeaderText="日期 " DataFormatString="{0:yyyy-MM-dd}">
    <HeaderStyle Font-Size="10pt" Width="5%"></HeaderStyle>
    </asp:BoundColumn>
    </Columns>
    <PagerStyle Visible="False" NextPageText="下一页" PrevPageText="上一页" HorizontalAlign="Left" ForeColor="#000066"
    BackColor="White" Mode="NumericPages"></PagerStyle>
    </asp:datagrid></DIV>
    </TD>
    </TR>
    <TR>
    <TD style="HEIGHT: 4px" vAlign="top"><FONT face="宋体"></FONT></TD>
    </TR>
    <TR>
    <TD style="HEIGHT: 3px" align="center" colSpan="1" rowSpan="1"><asp:button id="Button2" runat="server" Text="删除" Enabled="False"></asp:button><INPUT id="Reset1" type="reset" value="重置" name="Reset1" runat="server"></TD>
    </TR>
    <TR>
    <TD align="center"><FONT face="宋体"><webdiyer:aspnetpager id="AspNetPager1" runat="server" HorizontalAlign="Center" Wrap="False" TextBeforeInputBox="转到第"
    TextAfterInputBox="页" SubmitButtonText="GO" PageSize="6" ShowInputBox="Always" ShowCustomInfoSection="Left" alwaysShow="true"
    Font-Size="10"></webdiyer:aspnetpager></FONT></TD>
    </TR>
    </TABLE>
    <asp:label id="Message" style="Z-INDEX: 102; LEFT: 256px; POSITION: absolute; TOP: 80px" runat="server"
    Width="152px" Font-Size="15px" ForeColor="Red" Font-Bold="True"></asp:label><asp:label id="Message1" style="Z-INDEX: 103; LEFT: 136px; POSITION: absolute; TOP: 80px" runat="server"
    Width="88px" Font-Size="10pt" ForeColor="Red" Font-Bold="True"></asp:label>
    <asp:Button id="Button4" style="Z-INDEX: 105; LEFT: 56px; POSITION: absolute; TOP: 72px" runat="server"
    Text="Button"></asp:Button></form>
    </body>
    </HTML>
      

  10.   

    SqlConnection MyConnection = new SqlConnection("server=(local);database=bysj;Trusted_Connection=yes");
    string DeleteCmd = "DELETE FROM ygwage WHERE ygid = @ygid AND wagedate BETWEEN @LowerDate AND @UpperDate";
    //And dixin=@dixin";
    SqlCommand MyCommand = new SqlCommand(DeleteCmd, MyConnection);
    MyCommand.Parameters.Add("@ygid", SqlDbType.Int);MyCommand.Parameters.Add(new SqlParameter("@LowerDate", SqlDbType.DateTime));
    MyCommand.Parameters["@LowerDate"].Value = Convert.ToDateTime(TextBox2.Text);MyCommand.Parameters.Add(new SqlParameter("@UpperDate", SqlDbType.DateTime));
    MyCommand.Parameters["@UpperDate"].Value = Convert.ToDateTime(TextBox3.Text);             bool IsChecked = false; 
    // 此回圈判断哪些核取方块已被勾选,并将相对应的资料记录删除。
    foreach (DataGridItem CheckBoxItem in DataGrid1.Items)
    {   
    IsChecked = ((CheckBox)CheckBoxItem.FindControl("CB")).Checked;
    //if(IsChecked==false)
    //{
    //Page.RegisterStartupScript("Alert","<script language=javascript>alert('请选择要删除的项!');</script>");
    //}
    if (IsChecked) 
    {
    // 取得使用者欲删除之资料记录的主索引键(亦即员工编号)
    // 然後将它指派给 DELETE 命令叙述中的参数。
    MyCommand.Parameters["@ygid"].Value =DataGrid1.DataKeys[CheckBoxItem.ItemIndex];
    //MyCommand.Parameters["@dixin"].Value =DataGrid1.DataKeys[CheckBoxItem.ItemIndex];
    MyCommand.Connection.Open();
    try
    {
    // 呼叫 ExecuteNonQuery() 方法以便针对资料来源执行 DELETE 命令MyCommand.ExecuteNonQuery();
    Message1.Text = "成功删除";
    Message1.Visible=true;
    //Page.RegisterStartupScript("Alert","<script language=javascript>alert('成功删除!');</script>");
    }
    catch 
    //(SqlException)
    {
    Message.Text = "错误: 无法删除资料纪录";
    //Response.Write("<script>alert('删除失败!');history.back();</Script>");
    }
    MyCommand.Connection.Close();
    }
    }
    // 重新系结至资料来源
    BindGridToSource();
      

  11.   

    强烈鄙视这些恶(恶心的恶)人
    我的女同事上csdn每人这样说的
    垃圾