• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • ASP.NET高級教程(2.2):轉換編程思維

    發表于:2007-06-30來源:作者:點擊數: 標簽:
    這個bbs類很簡單,有四個私有變量,對應四個只讀屬性,方法只有一個帶參數的構造函數,作用是從 數據庫 中讀取相應的數據,填充四個私有變量。類構造好了,讓我們看看如何使用,在需要顯示論壇這些屬性的頁面文件里(.aspx)里,構造四個Label,象這樣: table
        
      這個bbs類很簡單,有四個私有變量,對應四個只讀屬性,方法只有一個帶參數的構造函數,作用是從數據庫中讀取相應的數據,填充四個私有變量。類構造好了,讓我們看看如何使用,在需要顯示論壇這些屬性的頁面文件里(.aspx)里,構造四個Label,象這樣:
      <table width=140 cellpadding=4 cellspacing=1 border=0>
      <tr>
      <td class=cn>
      <font color=white>注冊用戶數:</font>
      </td>
      <td>
      <asp:label id="lblUserCount" runat=Server class=cn></asp:label>
      </td>
      </tr>
      <tr>
      <td class=cn>
      <font color=white>貼子總數:</font>
      </td>
      <td>
      <asp:label id="lblTopicCount" runat=Server class=cn></asp:label>
      </td>
      </tr>
      <tr>
      <td class=cn>
      <font color=white>版面數:</font>
      </td>
      <td>
      <asp:label id="lblForumCount" runat=Server class=cn></asp:label>
      </td>
      </tr>
      </table>
      然后在對應的c#文件里這樣使用:
      
      protected void Page_Init(object sender, EventArgs e)
      {
      //
      // CODEGEN: This call is required by the ASP+ Windows Form Designer.
      //
      InitializeComponent();
      
      //初始化頁面對象
      //創建bbs對象
      try
      {
      m_objBBS = new BBS("鷹翔山莊論壇") ;
      }
      catch(Exception exp)
      {
      #if DEBUG
      Response.Write ("初始化bbs對象出錯:" + exp.Message + "<br>") ;
      return ;
      #endif//DEBUG
      Server.Transfer("error.aspx") ;
      }
      
      //論壇名稱
      lblBBSName.ForeColor = Color.White ;
      lblBBSName.Text = m_objBBS.Title ;
      
      //用戶數
      lblUserCount.ForeColor = Color.White ;
      lblUserCount.Text = m_objBBS.UserCount.ToString() ;
      
      //文章數
      lblTopicCount.ForeColor = Color.White ;
      lblTopicCount.Text = m_objBBS.TopicCount.ToString() ;
      
      //版面數
      lblForumCount.ForeColor = Color.White ;
      lblForumCount.Text = m_objBBS.ForumCount.ToString() ;
      }
      
      看出這樣使用的好處嗎?對,就是業務邏輯和html代碼分開,這樣無論頁面原型如何修改,代碼都不需要做絲毫改動。bbs對象構造好了,讓我們看看論壇的其他對象,他們分別是用戶(BBSUser)、版面(Forum)和貼子(Topic) , 我將在下節的內容里詳細解釋。
      
      
      

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>