⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewleavwords.aspx.cs

📁 asp.net 的某物流管理系统 MIS 系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class liuyan_Viewleavwords : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {      
        Showleavewords();
             
    }
    //显示留言,绑定控件
    private void Showleavewords()
    {
        DataSet ds = new DataSet();
        ds = Getleavewords();
        MyGridView.DataSource = ds.Tables["aa"].DefaultView;
        MyGridView.DataBind();
    }
    public bool Manage()
    {
        try
        {
            if (Session["Leaveword"].ToString() == "pass")
            {
                return true;
            }
        }
        catch
        {
        }
        return false;
    }
    //取留言
    public DataSet Getleavewords()
    {
        string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING3"].ConnectionString;
        OleDbConnection myConnection = new OleDbConnection(myConnectionString);
        string cmdText = "SELECT * FROM mydata ORDER BY CREATEDATE DESC";
        OleDbDataAdapter da = new OleDbDataAdapter(cmdText, myConnection);
        DataSet ds = new DataSet();
        try
        {
            myConnection.Open();
            da.Fill(ds, "aa");
        }
        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            myConnection.Close();
        }
        return ds;
    }
    //删除留言
    private void DelLeavewords(int nID)
    {
        string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING3"].ConnectionString;
        OleDbConnection myConnection = new OleDbConnection(myConnectionString);
        string cmdText = "DELETE FROM mydata WHERE LeavewordID=" + nID;
        OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection);
        try
        {
            myConnection.Open();
            myCommand.ExecuteNonQuery();
        }
        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            myConnection.Close();
        }
    }

   
    protected void MyGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "delete")
        {
            
            try
            {
                DelLeavewords(Int32.Parse(e.CommandArgument.ToString()));
                Showleavewords();
            }
            catch
            {              
            }
        }
        if (e.CommandName == "reply")
        {
            Response.Redirect("Reply.aspx?ShowID=" + e.CommandArgument.ToString());
        }
       
    }
    protected void MyGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }
    protected void MyGridView_RowDateBound(object sender, GridViewRowEventArgs e)
    {
        ImageButton deleteBtn = (ImageButton)e.Row.FindControl("delBtn");
        if (deleteBtn != null)
        {
            deleteBtn.Attributes.Add("onclick", "return confirm('你确定要删除所选择的留言吗?');");
        }
    }
    //翻页
    protected void MyGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        MyGridView.PageIndex = e.NewPageIndex;
        Showleavewords();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -