documentmanage.aspx.cs

来自「精通网络应用系统开发 光盘 该书是人民邮电出版社出版的」· CS 代码 · 共 93 行

CS
93
字号
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.Linq;
using System.Data;
using System.Collections.Generic;

public partial class DocumentManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!Page.IsPostBack)
		{
			///绑定控件的数据            
			BindDocumentData();
		}
		///添加删除确认对话框
		deleteBtn.Attributes.Add("onclick", "return confirm('" + ASPNET35System.OPERATIONDELETEMESSAGE + "');");
	}	

	private void BindDocumentData()
	{
		///定义获取数据的类
		DocumentM document = new DocumentM();
		IList<Document> recd = document.GetDocuments();

		///设定控件的数据源
		DocumentList.DataSource = recd;

		///设定控件的Text属性和Value属性
		DocumentList.DataTextField = "Desn";
		DocumentList.DataValueField = "DocumentID";

		///绑定控件的数据
		DocumentList.DataBind();

		///设置按钮的可用性
		updateBtn.Enabled = deleteBtn.Enabled = DocumentList.Items.Count <= 0 ? false : true;
	}

	protected void AddBtn_Click(object sender, EventArgs e)
	{
		///跳转到添加页面
		Response.Redirect("~/DesktopModules/Document/AddDocument.aspx");
	}

	protected void updateBtn_Click(object sender, ImageClickEventArgs e)
	{
		if (DocumentList.SelectedIndex <= -1)
		{
			///显示操作结果信息
			Response.Write("<script>window.alert('" + ASPNET35System.OPERATIONNOSELECTMESSAGE + "')</script>");
			return;
		}
		///跳转到修改页面
		Response.Redirect("~/DesktopModules/Document/UpdateDocument.aspx?DocumentID=" + DocumentList.SelectedValue);
	}

	protected void deleteBtn_Click(object sender, ImageClickEventArgs e)
	{
		if (DocumentList.SelectedIndex <= -1)
		{
			///显示操作结果信息
			Response.Write("<script>window.alert('" + ASPNET35System.OPERATIONNOSELECTMESSAGE + "')</script>");
			return;
		}

		///定义类
		DocumentM document = new DocumentM();
		try
		{
			///删除数据
			document.DeleteDocument(Int32.Parse(DocumentList.SelectedValue));
			///重新绑定数据
			BindDocumentData();
		}
		catch (Exception ex)
		{
			///显示删除操作中的失败、错误信息
			Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
				+ ASPNET35System.RedirectErrorUrl(Request.RawUrl)
				+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
		}
	}
}

⌨️ 快捷键说明

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