WebUserControl.ascx.cs
上传用户:tjxpgg
上传日期:2017-05-14
资源大小:2244k
文件大小:4k
源码类别:

SilverLight

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using Microsoft.Practices.EnterpriseLibrary.Common;
  12. using Microsoft.Practices.EnterpriseLibrary.Data;
  13. public partial class WebUserControl : System.Web.UI.UserControl
  14. {
  15.     Database DB = DatabaseFactory.CreateDatabase();
  16.     protected void Page_Load(object sender, EventArgs e)
  17.     {
  18.         this.btnFirst.Command += new CommandEventHandler(ClikMe);
  19.         this.btnPre.Command += new CommandEventHandler(ClikMe);
  20.         this.btnNext.Command += new CommandEventHandler(ClikMe);
  21.         this.btnLast.Command += new CommandEventHandler(ClikMe);
  22.         if (!IsPostBack)
  23.         {
  24.             ViewState["count"] = 1;
  25.             GetCount();
  26.             GetAllPage();
  27.             GetALLInfo();
  28.         }
  29.         
  30.     }
  31.     public void GetCount()
  32.     {
  33.         int AllInfo =Convert.ToInt32( DB.ExecuteScalar("GetRecordFromPage", this.TableName, "*",this.Column, this.PageSize, 1, 1, "asc", ""));
  34.         this.lblTolCount.Text = AllInfo.ToString();
  35.     }
  36.     public void GetAllPage()
  37.     {
  38.         int AllInfo = Convert.ToInt32(DB.ExecuteScalar("GetRecordFromPage", this.TableName, "*", this.Column, this.PageSize, 1, 1, "asc", ""));
  39.         int Page = 0;
  40.         if (AllInfo % 10 == 0)
  41.         {
  42.             Page = AllInfo / 10;
  43.         }
  44.         else
  45.         {
  46.             Page = AllInfo / 10 + 1;
  47.         }
  48.         this.lblPageCount.Text = Page.ToString();
  49.     }
  50.     public void GetALLInfo()
  51.     {
  52.         int index = Convert.ToInt32(ViewState["count"]);
  53.         (this.Page.FindControl(this.GridViewName) as Repeater).DataSource = DB.ExecuteDataSet("GetRecordFromPage", this.TableName, "*", this.Column, this.PageSize, index, 0, "asc", "");
  54.         (this.Page.FindControl(this.GridViewName) as Repeater).DataBind();
  55.     }
  56.     public string GridViewName
  57.     {
  58.         get { return ViewState["GridViewNam"].ToString(); }
  59.         set { ViewState["GridViewNam"] = value; }
  60.     }
  61.     public string TableName
  62.     {
  63.         get { return ViewState["TableName"].ToString(); }
  64.         set { ViewState["TableName"] = value; }
  65.     }
  66.     public int PageSize
  67.     {
  68.         get { return Convert.ToInt32(ViewState["PageSize"]); }
  69.         set { ViewState["PageSize"] = value; }
  70.     }
  71.     public string Column
  72.     {
  73.         get { return ViewState["column"].ToString(); }
  74.         set { ViewState["column"] = value; }
  75.     }
  76.     protected void ClikMe(object sender, CommandEventArgs e)
  77.     {
  78.         string name = e.CommandName;
  79.         if (name == "FirstCmd")
  80.         {
  81.             ViewState["count"] = 1;
  82.         }
  83.         else if (name == "PreCmd")
  84.         {
  85.             if (Convert.ToInt32(ViewState["count"]) == 1)
  86.             {
  87.                 ViewState["count"] = 1;
  88.             }
  89.             else
  90.             {
  91.                 ViewState["count"] = Convert.ToInt32(ViewState["count"]) - 1;
  92.             }
  93.         }
  94.         else if (name == "NextCmd")
  95.         {
  96.             if (Convert.ToInt32(ViewState["count"]) == Convert.ToInt32(this.lblPageCount.Text))
  97.             {
  98.                 ViewState["count"] = Convert.ToInt32(this.lblPageCount.Text);
  99.             }
  100.             else
  101.             {
  102.                 ViewState["count"] = Convert.ToInt32(ViewState["count"]) + 1;
  103.             }
  104.         }
  105.         else 
  106.         {
  107.             ViewState["count"] = Convert.ToInt32(this.lblPageCount.Text);
  108.         }
  109.         GetALLInfo();
  110.     }
  111.     protected void txtCurrentPage_TextChanged(object sender, EventArgs e)
  112.     {
  113.         ViewState["count"] = Convert.ToInt32(this.txtCurrentPage.Text);
  114.         (this.Page.FindControl(this.GridViewName) as Repeater).DataSource = DB.ExecuteDataSet("GetRecordFromPage", this.TableName, "*", this.Column, this.PageSize, Convert.ToInt32(ViewState["count"]), 0, "asc", "");
  115.         (this.Page.FindControl(this.GridViewName) as Repeater).DataBind();
  116.     }
  117. }