国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

用戶自定義控件的應用。

2024-07-21 02:24:17
字體:
來源:轉載
供稿:網友

asp.net中的 用戶自定義控件 特點 1:實現服用;2:方便創建(相對與組件)。 以下為一個分頁導航條的sample, 接見于webdiyer,相信很多人已經如雷貫耳了,我也不多介紹。本問只是簡單的 練習之作,沒有什么深奧的算法和架構。

----behindcode---------------------------------------------------------------------------------------------------------------

namespace gallonkit
{
 using system;
 using system.data;
 using system.drawing;
 using system.web;
 using system.web.ui.webcontrols;
 using system.web.ui.htmlcontrols;

 /// <summary>
 ///  pagebar 的摘要說明。
 /// </summary>
 
 public delegate void pagelocalbtn(uint index);

 public class pagebar : system.web.ui.usercontrol
 {
  protected system.web.ui.webcontrols.linkbutton linkbutton1;
  protected system.web.ui.webcontrols.linkbutton btn_fistpage;
  protected system.web.ui.webcontrols.linkbutton btn_lastpage;
  protected system.web.ui.webcontrols.linkbutton btn_prepage;
  protected system.web.ui.webcontrols.linkbutton btn_nextpage;
  protected system.web.ui.webcontrols.label lb_pagecount;
  protected system.web.ui.webcontrols.textbox tb_pageindex;
  protected system.web.ui.webcontrols.linkbutton btn_local;
  public pagelocalbtn localbtnclick;
  

  private void page_load(object sender, system.eventargs e)
  {
   // 在此處放置用戶代碼以初始化頁面
  
  }

  private bool isuint(string strint)
  {
   try
   {
    uint.parse(strint);
   }
   catch(exception e)
   {
    return false;
   }

   return true;
   
  }

  
  
  public uint pageindex
  {
   get{
    if (this.isuint(this.tb_pageindex.text.trim()))
       return uint.parse(this.tb_pageindex.text.trim());
    return 0;
    }

   set{
    if (this.isuint(value.tostring()))
     this.tb_pageindex.text = value.tostring();
    else
     throw new system.exception("頁數范圍不正確!");

   }
  }

  

  public uint pagecount
  {
   get
   {
    object obj = viewstate["pagecount__"];
    return (obj == null)?0:(uint)obj;
   }

   set
   {
    
    if (this.isuint(value.tostring()))
    {
     this.lb_pagecount.text = value.tostring();
     viewstate["pagecount__"] = value;
    }
    else
     throw new system.exception("頁數范圍不正確!");
   }

  }

  
  #region web 窗體設計器生成的代碼
  override protected void oninit(eventargs e)
  {
   //
   // codegen: 該調用是 asp.net web 窗體設計器所必需的。
   //
   initializecomponent();
   base.oninit(e);
  }
  
  /// <summary>
  ///  設計器支持所需的方法 - 不要使用代碼編輯器
  ///  修改此方法的內容。
  /// </summary>
  private void initializecomponent()
  {
   this.btn_fistpage.click += new system.eventhandler(this.btn_fistpage_click);
   this.btn_prepage.click += new system.eventhandler(this.btn_prepage_click);
   this.btn_nextpage.click += new system.eventhandler(this.btn_nextpage_click);
   this.btn_lastpage.click += new system.eventhandler(this.btn_lastpage_click);
   this.btn_local.click += new system.eventhandler(this.btn_local_click);
   this.load += new system.eventhandler(this.page_load);

  }
  #endregion

  private void enableallbtn()
  {
   this.btn_fistpage.enabled = true;
   this.btn_lastpage.enabled = true;
   this.btn_prepage.enabled  = true;
   this.btn_nextpage.enabled = true;

  }

  private void changebtnstatus(char btnindex)
  {
   switch(btnindex)
   {
    case 'f':
     this.btn_fistpage.enabled = false;
     this.btn_prepage.enabled = false;
     break;
    case 'l':
     this.btn_nextpage.enabled = false;
     this.btn_lastpage.enabled = false;
     break;
    case 'p':
     this.btn_prepage.enabled = false;
     break;
    case 'n':
     this.btn_nextpage.enabled = false;
     break;
   }
  }
  
  private void btn_lastpage_click(object sender, system.eventargs e)
  {
   enableallbtn();

   if( localbtnclick != null)
   {
    localbtnclick(this.pagecount);
   }

   this.changebtnstatus('l');
  }

  private void btn_fistpage_click(object sender, system.eventargs e)
  {
   enableallbtn();
   if( localbtnclick != null)
   {
    localbtnclick(1);
   }

   this.changebtnstatus('f');
  }

  private void btn_prepage_click(object sender, system.eventargs e)
  {
   enableallbtn();

   if (localbtnclick  == null) return;
   if (this.pageindex>1)
    this.pageindex--;
   else
   {
    this.changebtnstatus('p');
    this.changebtnstatus('f');
   }

   this.localbtnclick(this.pageindex);
  
  }

  private void btn_nextpage_click(object sender, system.eventargs e)
  {
   enableallbtn();
   if (localbtnclick  == null) return;
   if (this.pageindex<this.pagecount)
    this.pageindex++;
   else
   {
    this.changebtnstatus('n');
    this.changebtnstatus('l');

   }

   this.localbtnclick(this.pageindex);
  }

  private void btn_local_click(object sender, system.eventargs e)
  {
   enableallbtn();
   if (this.pageindex <=1)
   {
    this.tb_pageindex.text = "1";
    this.changebtnstatus('f');
   }
   else
   {
    if(this.pageindex >= this.pagecount )
    {
     this.pageindex = this.pagecount;
     this.changebtnstatus('l');
    }
   }

   if( localbtnclick != null)
    localbtnclick(this.pageindex);
   
  }
 }
}
====================aspx文件=====================================================



 | 首頁 | 前頁 | 后頁 | 末頁 |1 go |總頁數

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 萍乡市| 临清市| 建阳市| 宁蒗| 四子王旗| 西贡区| 新兴县| 柳河县| 宁强县| 翁牛特旗| 涟源市| 武强县| 山丹县| 花莲县| 凯里市| 南通市| 万载县| 汝阳县| 瑞金市| 凤山市| 杭锦旗| 贡嘎县| 云和县| 两当县| 大化| 巴林左旗| 扎兰屯市| 定襄县| 同江市| 六盘水市| 抚松县| 汉沽区| 五家渠市| 盘山县| 焉耆| 桑日县| 乐清市| 文昌市| 简阳市| 大厂| 鹤山市|