📄 info.aspx.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.SqlClient;
using System.IO;
public partial class InFo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=;Database=mrdb");
con.Open();
SqlDataAdapter ada = new SqlDataAdapter("select * from tb_files", con);
DataSet ds = new DataSet();
ada.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataKeyNames = new string[] { "name" };
GridView1.DataBind();
con.Close();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=;Database=mrdb");
con.Open();
SqlDataAdapter ada = new SqlDataAdapter("select * from tb_files where name='" + this.GridView1.DataKeys[e.RowIndex].Value.ToString() + "'", con);
DataSet ds = new DataSet();
ada.Fill(ds, "tb_files");
DataRow[] row = ds.Tables[0].Select();
foreach (DataRow rs in row)
{
if (rs["name"].ToString() != "")
{
FileInfo file = new FileInfo(Server.MapPath("Files/" + rs["name"].ToString()));
file.Delete();
}
}
SqlCommand com = new SqlCommand("delete from tb_files where name='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'", con);
com.ExecuteNonQuery();
Page_Load(sender, e);
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondblclick", "window.open('ParticularInfo.aspx?id=" + e.Row.Cells[0].Text + "')");//双击行打开新页
((LinkButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick","return confirm('确定要删除吗?')");//确定删除消息提示
e.Row.Cells[2].Text = DateTime.Parse(e.Row.Cells[2].Text).ToString("yyyy-MM-dd");//格式化日期
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"" + e.Row.Style["BACKGROUND-COLOR"] + "\"");//鼠标随行而变色
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"" + "#9FACCF" + "\"");//鼠标随行而变色
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -