WebUserControl.ascx.cs
资源名称:SunShine.rar [点击查看]
上传用户:tjxpgg
上传日期:2017-05-14
资源大小:2244k
文件大小:4k
源码类别:
SilverLight
开发平台:
ASP/ASPX
- 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 Microsoft.Practices.EnterpriseLibrary.Common;
- using Microsoft.Practices.EnterpriseLibrary.Data;
- public partial class WebUserControl : System.Web.UI.UserControl
- {
- Database DB = DatabaseFactory.CreateDatabase();
- protected void Page_Load(object sender, EventArgs e)
- {
- this.btnFirst.Command += new CommandEventHandler(ClikMe);
- this.btnPre.Command += new CommandEventHandler(ClikMe);
- this.btnNext.Command += new CommandEventHandler(ClikMe);
- this.btnLast.Command += new CommandEventHandler(ClikMe);
- if (!IsPostBack)
- {
- ViewState["count"] = 1;
- GetCount();
- GetAllPage();
- GetALLInfo();
- }
- }
- public void GetCount()
- {
- int AllInfo =Convert.ToInt32( DB.ExecuteScalar("GetRecordFromPage", this.TableName, "*",this.Column, this.PageSize, 1, 1, "asc", ""));
- this.lblTolCount.Text = AllInfo.ToString();
- }
- public void GetAllPage()
- {
- int AllInfo = Convert.ToInt32(DB.ExecuteScalar("GetRecordFromPage", this.TableName, "*", this.Column, this.PageSize, 1, 1, "asc", ""));
- int Page = 0;
- if (AllInfo % 10 == 0)
- {
- Page = AllInfo / 10;
- }
- else
- {
- Page = AllInfo / 10 + 1;
- }
- this.lblPageCount.Text = Page.ToString();
- }
- public void GetALLInfo()
- {
- int index = Convert.ToInt32(ViewState["count"]);
- (this.Page.FindControl(this.GridViewName) as Repeater).DataSource = DB.ExecuteDataSet("GetRecordFromPage", this.TableName, "*", this.Column, this.PageSize, index, 0, "asc", "");
- (this.Page.FindControl(this.GridViewName) as Repeater).DataBind();
- }
- public string GridViewName
- {
- get { return ViewState["GridViewNam"].ToString(); }
- set { ViewState["GridViewNam"] = value; }
- }
- public string TableName
- {
- get { return ViewState["TableName"].ToString(); }
- set { ViewState["TableName"] = value; }
- }
- public int PageSize
- {
- get { return Convert.ToInt32(ViewState["PageSize"]); }
- set { ViewState["PageSize"] = value; }
- }
- public string Column
- {
- get { return ViewState["column"].ToString(); }
- set { ViewState["column"] = value; }
- }
- protected void ClikMe(object sender, CommandEventArgs e)
- {
- string name = e.CommandName;
- if (name == "FirstCmd")
- {
- ViewState["count"] = 1;
- }
- else if (name == "PreCmd")
- {
- if (Convert.ToInt32(ViewState["count"]) == 1)
- {
- ViewState["count"] = 1;
- }
- else
- {
- ViewState["count"] = Convert.ToInt32(ViewState["count"]) - 1;
- }
- }
- else if (name == "NextCmd")
- {
- if (Convert.ToInt32(ViewState["count"]) == Convert.ToInt32(this.lblPageCount.Text))
- {
- ViewState["count"] = Convert.ToInt32(this.lblPageCount.Text);
- }
- else
- {
- ViewState["count"] = Convert.ToInt32(ViewState["count"]) + 1;
- }
- }
- else
- {
- ViewState["count"] = Convert.ToInt32(this.lblPageCount.Text);
- }
- GetALLInfo();
- }
- protected void txtCurrentPage_TextChanged(object sender, EventArgs e)
- {
- ViewState["count"] = Convert.ToInt32(this.txtCurrentPage.Text);
- (this.Page.FindControl(this.GridViewName) as Repeater).DataSource = DB.ExecuteDataSet("GetRecordFromPage", this.TableName, "*", this.Column, this.PageSize, Convert.ToInt32(ViewState["count"]), 0, "asc", "");
- (this.Page.FindControl(this.GridViewName) as Repeater).DataBind();
- }
- }