日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

中國最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2

aspnet教程

  • ASP.NET 教程
  • ASP.NET 簡介
  • ASP.NET Razor

    ASP.NET MVC

    ASP.NET 編程指南

    ASP.NET 數(shù)據(jù)綁定

    閱讀 (2353)

    ASP.NET - 數(shù)據(jù)綁定

    每一個 ASP.NET 網(wǎng)頁表單控件從它的父控件類繼承了 DataBind 方法,它給予了它繼承的能力來綁定數(shù)據(jù)到它屬性中的至少一個屬性。這就是所謂的簡單數(shù)據(jù)綁定或者內(nèi)部數(shù)據(jù)綁定

    簡單數(shù)據(jù)綁定包括將任何實現(xiàn) IEnumerable 接口的集合(項目集合),或者 DataSet 和 DataTable 類附加到控件的 DataSource 屬性。

    另一方面,一些控件可以通過 DataSource 控件綁定記錄,列表,或者數(shù)據(jù)列到它們的結(jié)構(gòu)中。這些控件源自 BaseDataBoundControl 類。這被叫做描述性數(shù)據(jù)綁定

    data source 控件幫助 data-bound 控件實現(xiàn)了比如排序,分頁和編輯數(shù)據(jù)集合的功能。

    BaseDataBoundControl 是一個抽象類,它通過兩個抽象類繼承:

    • DataBoundControl
    • HierarchicalDataBoundControl

    抽象類 DataBoundControl 也由兩個抽象類繼承:

    • ListControl
    • CompositeDataBoundControl

    能夠簡單綁定數(shù)據(jù)的控件源自 ListControl 抽象類并且這些控件是:

    • BulletedList
    • CheckBoxList
    • DropDownList
    • ListBox
    • RadioButtonList

    能夠描述性數(shù)據(jù)綁定的控件(一個更復(fù)雜的數(shù)據(jù)綁定)源自抽象類 CompositeDataBoundControl。這是控件是:

    • DetailsView
    • FormView
    • GridView
    • RecordList

    簡單數(shù)據(jù)綁定

    簡單數(shù)據(jù)綁定包括只讀選擇列表。這些控件能綁定一個數(shù)組列或者數(shù)據(jù)庫的字段。選擇列表從數(shù)據(jù)庫中或 data source 中取兩個值;一個值用過列表表示而另一個被認(rèn)為是相應(yīng)顯示的值。

    讓我們使用一個小例子來理解這個概念。用一個項目符號列表和一個 SqlDataSource 控件來創(chuàng)建一個網(wǎng)頁。配置 data source 控件來從你的數(shù)據(jù)庫中(我們在之前的章節(jié)中使用相同的 DotNetReferences 表)檢索兩個值。

    為包含的項目符號列表控件選擇一個 data source:

    • 選擇 data source 控件
    • 選擇一個字段來展示,它被叫做數(shù)據(jù)字段
    • 選擇值的字段

    1

    當(dāng)應(yīng)用程序執(zhí)行的時候,檢查整個標(biāo)題列綁定到項目符號列表并被展示。

    2

    描述性數(shù)據(jù)綁定

    我們已經(jīng)在之前的指南中使用 GridView 控件來使用描述性數(shù)據(jù)綁定。其他復(fù)合的能夠以表格的方式展示并操作數(shù)據(jù)的 data bound 控件是 DetailsView, FormView 和 RecordList 控件。

    在下一個指南中,我們將研究解決數(shù)據(jù)庫,i.e,ADO.NET 的 技術(shù)。

    但是,數(shù)據(jù)綁定包括以下對象:

    • 存儲從數(shù)據(jù)庫檢索數(shù)據(jù)的數(shù)據(jù)集。
    • 數(shù)據(jù)提供者,它通過使用一個連接的命令從數(shù)據(jù)庫中檢索數(shù)據(jù)。
    • 發(fā)出存儲在 command 對象中的選擇語句的數(shù)據(jù)適配器;它也能通過發(fā)出 Insert,Delete,和 Updata 語句來更新數(shù)據(jù)庫中的數(shù)據(jù)。

    data bonding 對象間的關(guān)系:

    3

    例子

    讓我們采取以下的步驟:

    步驟(1):創(chuàng)建一個新的網(wǎng)頁。通過右擊在 Solution Explorer 上的 solution 名字和從 'Add Item' 對話框中選擇項目 'Class' 來添加一個名為 booklist 的類。將它命名為 booklist.cs。

    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    
    using System.Xml.Linq;
    
    namespace databinding
    {
       public class booklist
       {
          protected String bookname;
          protected String authorname;
          public booklist(String bname, String aname)
          {
             this.bookname = bname;
             this.authorname = aname;
    
          }
    
          public String Book
          {
             get
             {
                return this.bookname;
             }
             set
             {
                this.bookname = value;
             }
          }
    
          public String Author
          {
             get
             {
                return this.authorname;
             }
             set
             {
                this.authorname = value;
             }
          }
       }
    }

    步驟(2):在頁面上添加四個列表控件,一個 list box 控件,一個 radio button 控件,一個 check box 控件和一個 drop down list 和四個與這些列表控件一起的四個表單。在設(shè)計視圖中頁面應(yīng)該看起來像這樣:

    4

    源文件應(yīng)該看起來像下面這樣:

    <form id="form1" runat="server">
       <div>
    
          <table style="width: 559px">
             <tr>
                <td style="width: 228px; height: 157px;">
                   <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" 
                      OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
                   </asp:ListBox>
                </td>
    
                <td style="height: 157px">
                   <asp:DropDownList ID="DropDownList1" runat="server" 
                      AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                   </asp:DropDownList>
                </td>             
             </tr>
    
             <tr>
                <td style="width: 228px; height: 40px;">
                   <asp:Label ID="lbllistbox" runat="server"></asp:Label>
                </td>
    
                <td style="height: 40px">
                   <asp:Label ID="lbldrpdown" runat="server">
                   </asp:Label>
                </td>
             </tr>
    
             <tr>
                <td style="width: 228px; height: 21px">
                </td>
    
                <td style="height: 21px">
                </td>              
             </tr>
    
             <tr>
                <td style="width: 228px; height: 21px">
                   <asp:RadioButtonList ID="RadioButtonList1" runat="server"
                      AutoPostBack="True"  OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                   </asp:RadioButtonList>
                </td>
    
                <td style="height: 21px">
                   <asp:CheckBoxList ID="CheckBoxList1" runat="server" 
                      AutoPostBack="True" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
                   </asp:CheckBoxList>
                </td>                
             </tr>
    
             <tr>
                <td style="width: 228px; height: 21px">
                   <asp:Label ID="lblrdlist" runat="server">
                   </asp:Label>
                </td>
    
                <td style="height: 21px">
                   <asp:Label ID="lblchklist" runat="server">
                   </asp:Label>
                </td>           
             </tr>
          </table>      
    
       </div>
    </form>

    步驟(3):最后,在應(yīng)用程序的例行程序后寫下面的代碼:

    public partial class _Default : System.Web.UI.Page
    {
       protected void Page_Load(object sender, EventArgs e)
       {
          IList bklist = createbooklist();
    
          if (!this.IsPostBack)
          {
             this.ListBox1.DataSource = bklist;
             this.ListBox1.DataTextField = "Book";
             this.ListBox1.DataValueField = "Author";
    
             this.DropDownList1.DataSource = bklist;
             this.DropDownList1.DataTextField = "Book";
             this.DropDownList1.DataValueField = "Author";
    
             this.RadioButtonList1.DataSource = bklist;
             this.RadioButtonList1.DataTextField = "Book";
             this.RadioButtonList1.DataValueField = "Author";
    
             this.CheckBoxList1.DataSource = bklist;
             this.CheckBoxList1.DataTextField = "Book";
             this.CheckBoxList1.DataValueField = "Author";
    
             this.DataBind();
          }
       }
    
       protected IList createbooklist()
       {
          ArrayList allbooks = new ArrayList();
          booklist bl;
    
          bl = new booklist("UNIX CONCEPTS", "SUMITABHA DAS");
          allbooks.Add(bl);
    
          bl = new booklist("PROGRAMMING IN C", "RICHI KERNIGHAN");
          allbooks.Add(bl);
    
          bl = new booklist("DATA STRUCTURE", "TANENBAUM");
          allbooks.Add(bl);
    
          bl = new booklist("NETWORKING CONCEPTS", "FOROUZAN");
          allbooks.Add(bl);
    
          bl = new booklist("PROGRAMMING IN C++", "B. STROUSTROUP");
          allbooks.Add(bl);
    
          bl = new booklist("ADVANCED JAVA", "SUMITABHA DAS");
          allbooks.Add(bl);
    
          return allbooks;
       }
    
       protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
       {
          this.lbllistbox.Text = this.ListBox1.SelectedValue;
       }
    
       protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
       {
          this.lbldrpdown.Text = this.DropDownList1.SelectedValue;
       }
    
       protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
       {
          this.lblrdlist.Text = this.RadioButtonList1.SelectedValue;
       }
    
       protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
       {
          this.lblchklist.Text = this.CheckBoxList1.SelectedValue;
       }
    }

    觀察以下:

    • booklist 類有兩個屬性:bookname 和 authorname。
    • createbooklist 方法是一個用戶定義的可以創(chuàng)建名為 allboods 的 booklist 類的數(shù)組的方法。
    • Page_Load 事件句柄確保了 books 的列表被創(chuàng)建。該列表是 IList 型的,它實現(xiàn)了 IEnumerable 接口并能和列表控件綁定。Page load 時間句柄用控件綁定了 IList 對象'bklist'。bookname 屬性被展示并且 authorname 屬性被視為這個值。  
    • 當(dāng)頁面運(yùn)行時,如果用戶選擇了一本書,則它的名字被選擇并且通過 list 控件被顯示出來,而相應(yīng)的標(biāo)簽顯示作者的名字,它是 list 控件所選擇的相應(yīng)的值。

    5

    關(guān)閉
    程序員人生
    主站蜘蛛池模板: 最近中文字幕mv免费高清在线 | 亚洲成人三区 | 成人手机在线免费视频 | 成人午夜视频网站 | 视频一区欧美 | 91啪国产在线 | 国产一级免费 | 日干夜干 | 欧美极品一区二区 | 欧美黑人性视频 | 精品久久久久久 | 一区中文字幕 | 成人在线播放 | 噜噜社 | 国产成人免费视频 | 国产精品亚洲综合 | 国内精品久久久久影院薰衣草 | 黄色录像a级 | 久久99亚洲精品 | 国产在线不卡 | 欧美在线免费 | 久久久久成人精品 | 99久久爱| 久久99国产精品久久99大师 | 在线看v片| 欧美日韩激情在线一区二区三区 | 欧美日韩精品一二三区 | 一级免费视频 | 亚洲欧美日韩天堂 | 欧美激情综合五月色丁香小说 | 国产三级一区 | 99热综合 | 日韩视频免费观看 | 国产真实乱偷精品视频免 | 青草福利视频 | 日韩a在线播放 | 亚洲精品视频自拍 | 久久久久国产一区二区三区四区 | 97偷拍视频 | 欧美激情在线精品一区二区三区 | 午夜精品一区 |