用DATEGRID作表格,最后一列是checkbox,不知道如何可以实现选中checkbox 删除按钮按下,可以将其删除,代码如何实现,还有翻页的功能 也不知如何实现,哪位高手能有原代码? 谢谢

解决方案 »

  1.   

    foreach(DataGridItem thisItem in DataGridOptLog.Items)
    {
    if(((CheckBox)thisItem.Cells[0].Controls[1]).Checked) 
    {
    int LogID = Convert.ToInt16(DataGridOptLog.DataKeys[thisItem.ItemIndex]);

    DelOptLog(LogID);
    }
    }
    this.WriteOptLog("删除操作日志信息");
    JScript.Alert("删除成功!");
    if( DataGridOptLog.CurrentPageIndex == DataGridOptLog.PageCount-1)
    DataGridOptLog.CurrentPageIndex =DataGridOptLog.CurrentPageIndex-1;
    MyBindData();
      

  2.   

    <HTML>
    <HEAD>
    <title>userlog</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <LINK href="../Style/lynn.css" type="text/css" rel="stylesheet">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="userlog" method="post" runat="server">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td height="30"></td>
    </tr>
    </table>
    <br>
    <br>
    <TABLE id="Table1" style=" WIDTH: 179px; TOP: 150px; HEIGHT: 26px" cellSpacing="0" cellPadding="0"
    width="179" border="0">
    <TR>
    <TD>
    <asp:panel id="Panel1" runat="server" Width="699px" Height="341px">
    <TABLE id="Table3" style="WIDTH: 657px; HEIGHT: 382px" cellSpacing="0" cellPadding="0"
    width="657" align="center" border="0">
    <TBODY>
    <TR>
    <TD><FONT face="宋体">&nbsp;&nbsp; </FONT><FONT color="#0033ff"><FONT face="宋体"></FONT>
    <TABLE id="Table5" style="WIDTH: 100%; HEIGHT: 26px" cellSpacing="0" cellPadding="0" width="692"
    border="0">
    <TBODY>
    <TR>
    <TD style="WIDTH: 12px"><FONT face="宋体"><IMG src="img/tbtopleft.gif"></FONT></TD>
    <TD style="BACKGROUND-IMAGE: url(img/tbtop(xi).gif); WIDTH: 45%"><FONT face="宋体" color="#0033ff" size="2">操作日志</FONT></TD>
    <TD style="BACKGROUND-IMAGE: url(img/tp_bg.gif); VERTICAL-ALIGN: super; WIDTH: 4.67%; BACKGROUND-REPEAT: repeat-x; TEXT-ALIGN: left"
    align="center">
    <P><FONT style="TEXT-ALIGN: center"><FONT style="TEXT-ALIGN: center"><FONT style="VERTICAL-ALIGN: super"><FONT style="TEXT-ALIGN: center"><FONT style="TEXT-ALIGN: center"><FONT style="VERTICAL-ALIGN: baseline"><FONT face="宋体"><IMG height="25" src="img/top_corner.gif"></FONT></P>
    </FONT></FONT></FONT></FONT></FONT></FONT></TD>
    <TD style="BACKGROUND-IMAGE: url(img/tp_bg.gif); WIDTH: 55%; BACKGROUND-REPEAT: repeat-x; TEXT-ALIGN: center"
    align="center"><FONT face="宋体"></FONT></TD>
    <TD align="right"><FONT face="宋体"><IMG src="img/point_corner.gif"></FONT></TD>
    </TR>
    </TBODY>
    </TABLE>
    <TABLE id="Table4" style="BACKGROUND-IMAGE: none; HEIGHT: 7px" height="7" cellSpacing="0"
    cellPadding="0" width="100%" border="0">
    <TR>
    <TD style="WIDTH: 6px; BACKGROUND-REPEAT: no-repeat; HEIGHT: 257px"><FONT face="宋体"></FONT></TD>
    <TD style="BACKGROUND-IMAGE: url(img/left_bg.gif); WIDTH: 33px; BACKGROUND-REPEAT: repeat-y; HEIGHT: 257px"><FONT face="宋体"></FONT></TD>
    <TD style="WIDTH: 99.73%; BACKGROUND-REPEAT: repeat-x; HEIGHT: 257px" bgColor="#f0f7ff">
    <DIV style="WIDTH: 640px; POSITION: relative; HEIGHT: 282px" ms_positioning="GridLayout">
    <P><FONT face="宋体"></FONT>&nbsp;</P>
    <asp:datagrid id="DataGridOptLog" style="Z-INDEX: 104; LEFT: 0px; POSITION: absolute; TOP: 42px"
    runat="server" Width="639px" Height="240px" DataKeyField="pkid" AllowPaging="True" PageSize="8"
    AutoGenerateColumns="False">
    <AlternatingItemStyle CssClass="gridalteritem"></AlternatingItemStyle>
    <ItemStyle CssClass="griditem"></ItemStyle>
    <HeaderStyle CssClass="headcenter" BackColor="#FFF7CE"></HeaderStyle>
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:CheckBox id="CheckBox1" runat="server"></asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="number" HeaderText="序号"></asp:BoundColumn>
    <asp:BoundColumn DataField="OperatorID" HeaderText="用户ID"></asp:BoundColumn>
    <asp:BoundColumn DataField="OperatorName" HeaderText="用户姓名"></asp:BoundColumn>
    <asp:BoundColumn DataField="OperateTime" HeaderText="操作时间"></asp:BoundColumn>
    <asp:BoundColumn DataField="FuncName" HeaderText="操作模块"></asp:BoundColumn>
    <asp:BoundColumn DataField="OperationDescription" HeaderText="操作描述"></asp:BoundColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Right" PageButtonCount="5" Mode="NumericPages"></PagerStyle>
    </asp:datagrid>
    <asp:CheckBox id="CheckBox2" runat="server" style="Z-INDEX: 103; LEFT: 281px; POSITION: absolute; TOP: 0px"
    Font-Size="X-Small" AutoPostBack="True" Text="选择当前页面的所有记录"></asp:CheckBox>
    <asp:imagebutton id="ImgBdel" style="Z-INDEX: 103; LEFT: 481px; POSITION: absolute; TOP: 0px" runat="server"
    ImageUrl="../img/del.jpg"></asp:imagebutton><FONT face="宋体"></FONT></DIV>
    </TD>
    <TD style="BACKGROUND-POSITION-X: right; BACKGROUND-IMAGE: url(img/right_bg.gif); WIDTH: 6px; BACKGROUND-REPEAT: repeat-y; HEIGHT: 257px"><FONT style="BACKGROUND-IMAGE: url(img/tb_rightbg.gif); BACKGROUND-REPEAT: repeat-y"><FONT style="BACKGROUND-IMAGE: url(img/tb_rightbg.gif); BACKGROUND-REPEAT: repeat-y"></FONT></FONT><FONT face="宋体">&nbsp;</FONT></FONT></TD>
    </TR>
    <TR>
    <TD style="BACKGROUND-IMAGE: url(img/corner_left_l.gif); WIDTH: 6px; BACKGROUND-REPEAT: no-repeat; HEIGHT: 6px"><FONT face="宋体"></FONT></TD>
    <TD><FONT face="宋体"><IMG src="img/corner_ll.gif"></FONT></TD>
    <TD style="BACKGROUND-IMAGE: url(img/bot_bg.gif); WIDTH: 99.87%; BACKGROUND-REPEAT: repeat-x; HEIGHT: 12px"><FONT face="宋体"></FONT></TD>
    <TD style="BACKGROUND-IMAGE: none; WIDTH: 12px; HEIGHT: 13px"><FONT face="宋体"><IMG src="img/corner_r.gif"></FONT></TD>
    </TR>
    </TABLE></FONT></TD>
    </TR>
    </TABLE>
    </asp:panel></TD></TR></TBODY></TABLE>
    </form>
    </body>
    </HTML>
      

  3.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace AAS2.SYS
    {
    /// <summary>
    /// OperationLog 的摘要说明。
    /// </summary>
    public class OperationLog : AasBase
    {
    protected System.Web.UI.WebControls.Panel Panel1;
    protected System.Web.UI.WebControls.ImageButton ImgBdel;
    protected System.Web.UI.WebControls.DataGrid DataGridOptLog;
    protected System.Web.UI.WebControls.CheckBox CheckBox2; private void Page_Load(object sender, System.EventArgs e)
    {
    this.PageBegin("操作日志",true); if(Page.IsPostBack ==false)
    {
    DataGridOptLogBind();
    }
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.DataGridOptLog.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGridOptLog_PageIndexChanged);
    this.DataGridOptLog.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGridOptLog_ItemDataBound);
    this.CheckBox2.CheckedChanged += new System.EventHandler(this.CheckBox2_CheckedChanged);
    this.ImgBdel.Click += new System.Web.UI.ImageClickEventHandler(this.ImgBdel_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion public void MyBindData()
    {
    LogDB myclass= new LogDB ();
    DataTable mytable=myclass.ReadOperationLog();
    DataColumn  mycolumn=  mytable.Columns.Add ("number",System.Type .GetType ("System.String"));
    for (int i=0;i<mytable.Rows.Count ;i++)
    {
    mytable.Rows [i]["number"]=(i+1).ToString ();
    }
    DataGridOptLog.DataSource =mytable;
    DataGridOptLog.DataBind ();
    } public void DataGridOptLogBind()
    {
    DataGridOptLog.CurrentPageIndex =0;
    MyBindData();
    } public void DelOptLog(int pkid)
    {
    LogDB myclass= new LogDB ();
    myclass.DelOptLog(pkid);
    } private void ImgBdel_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
    if(this.EmpRightCode == 4)
    {
    foreach(DataGridItem thisItem in DataGridOptLog.Items)
    {
    if(((CheckBox)thisItem.Cells[0].Controls[1]).Checked) 
    {
    int LogID = Convert.ToInt16(DataGridOptLog.DataKeys[thisItem.ItemIndex]);

    DelOptLog(LogID);
    }
    }
    this.WriteOptLog("删除操作日志信息");
    JScript.Alert("删除成功!");
    if( DataGridOptLog.CurrentPageIndex == DataGridOptLog.PageCount-1)
    DataGridOptLog.CurrentPageIndex =DataGridOptLog.CurrentPageIndex-1;
    MyBindData();
    }
    else
    {
    JScript.Alert("您没有权限进行此操作!");
    }
    } private void DataGridOptLog_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    ListItemType itemType = e.Item.ItemType;
    if (itemType == ListItemType.Item )
    {

    e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#dedfde';";
    e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';" ; }
    else if( itemType == ListItemType.AlternatingItem)
    {
    e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';";
    e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';" ;
    }
    } private void DataGridOptLog_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    DataGridOptLog.CurrentPageIndex =e.NewPageIndex ;
    MyBindData();
    } private void CheckBox2_CheckedChanged(object sender, System.EventArgs e)
    {
    foreach(DataGridItem thisItem in DataGridOptLog.Items)
    {
    ((CheckBox)thisItem.Cells[0].Controls[1]).Checked = CheckBox2.Checked;
    } }
    }
    }