6.5 资源管理的设计与实现
6.5.2 资源管理的程序实现
以下是资源管理页面Resource.aspx的后台代码(Resource.aspx.cs):
......
using DataAccess;
namespace workflow.admin
{
public class Resource : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.HtmlControls.HtmlGenericControl Message;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
//验证用户是否登录
if(Session["userid"] == null)
Response.Redirect("./Message.aspx");
BindGrid();
BindList();
}
//span控件,显示程序异常信息
Message.InnerHtml="";
//用于显示程序异常信息
Label1.Text="";
}
//设置DataGrid控件的数据源并绑定数据
void BindGrid()
{
string strSql="select *,isnull((select CategoryName from ResourceCategories where
CategoryID=(select InheritedCategoryID from ResourceCategories where
CategoryID=ResourceType))+':','')+isnull((select CategoryName from
ResourceCategories where CategoryID=ResourceType),'') as
fullcategoryname from Resource order by ResourceType";
//Sql语句说明: 子句是在资源分类表中获取特定资源类的父类,其中ResourceType是资源表
//Resource当前记录的资源类别编号;两个isnull()子句分别获得资源的父类和类别名称
DataSet ds=new Base().SQLExeDataSet(strSql);
if(ds !=null)
{
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
//这里用viewstate存储数据集,如果用普通变量,当aspx页面重新加载后,上一次存放在
//变量中的数据就会丢失。视图状态viewstate类似静态变量,是存储在客户端的隐藏信息,
//当服务器接受页面回传时将访问viewstate内容。服务器端控件的属性中都有viewstate,
//只需将其设置为true即可,就可以保存控件信息.
ViewState["datasource"]=ds;
}
}
//DropDownList1控件绑定数据