濮阳杆衣贸易有限公司

主頁 > 知識庫 > ASP.NET數(shù)據(jù)綁定之Repeater控件

ASP.NET數(shù)據(jù)綁定之Repeater控件

熱門標(biāo)簽:塔城代理外呼系統(tǒng) 地圖標(biāo)注專業(yè)團(tuán)隊 天心智能電銷機(jī)器人 地圖定位圖標(biāo)標(biāo)注 400電話辦理哪家性價比高 遂寧市地圖標(biāo)注app 濮陽外呼電銷系統(tǒng)怎么樣 代理接電話機(jī)器人如何取消 地圖標(biāo)注的公司有哪些

在ASP.NET的學(xué)習(xí)過程中,其控件的學(xué)習(xí)和使用占了很大的一部分,本文為大家介紹一下控件Repeater控件的使用,用它來綁定后臺數(shù)據(jù),然后在客戶端(瀏覽器)上顯示出來!
一、 Repeater控件

1、用途:使用模板循環(huán)顯示數(shù)據(jù)。
2、包含的模板:

  • ItemTemplate>/ItemTemplate> 項目模板(里面的數(shù)據(jù)正常顯示)
  • AlternatingItemTemplate>/AlternatingItemTemplate> 交錯顯示模板(里面綁定的數(shù)據(jù)交錯著顯示)FooterTemplate>/FooterTemplate>頁腳模板(編輯頁腳)
  • HeaderTemplate>/HeaderTemplate>頁眉模板(編輯頁眉)
  • SeparatorTemplate>/SeparatorTemplate>間隔模板 (在顯示的數(shù)據(jù)中插入間隔,像橫線、特殊符號等等)

 二、示例

1、內(nèi)容介紹
     將數(shù)據(jù)庫中Person表中的信息選出來,然后用Repeater控件在客戶端顯示出來。下圖是我Sqlser數(shù)據(jù)庫中person表中的信息。

     

1)、將數(shù)據(jù)庫中的信息選出來并在后臺綁定: 新建Web窗體應(yīng)用程序,添加窗體,在窗體的Page_Load事件中添加如下代碼。

protected void Page_Load(object sender, EventArgs e) 
 { 
  SqlConnection con = DB.createConnection(); 
  SqlDataAdapter sda = new SqlDataAdapter(); 
  string sql="select * from person "; 
  sda.SelectCommand = new SqlCommand(sql, con); 
  DataSet ds=new DataSet(); 
  sda.Fill(ds, "per"); 
  this.Repeater1.DataSource=ds.Tables["per"]; 
  Repeater1.DataBind(); 
 } 

2)、用控件Repeater的模板  ItemTemplate>/ItemTemplate>   將信息顯示,代碼如下

asp:Repeater ID="Repeater1" runat="server"> 
  ItemTemplate> 
   p align="center"> 
   %# DataBinder.Eval(Container.DataItem,"pID") %> 
   %# DataBinder.Eval(Container.DataItem,"personName") %> 
   %# DataBinder.Eval(Container.DataItem,"personSex") %> 
   /p> 
  /ItemTemplate> 
  /asp:Repeater> 

3)、顯示效果如下

4)、AlternatingItemTemplate>/AlternatingItemTemplate>模板使用(讓數(shù)據(jù)交叉顯示)

asp:Repeater ID="Repeater1" runat="server"> 
  AlternatingItemTemplate> 
   p align="center"> 
   font color="blue"> %# DataBinder.Eval(Container.DataItem,"pID") %> 
   %# DataBinder.Eval(Container.DataItem,"personName") %> 
   %# DataBinder.Eval(Container.DataItem,"personSex") %>/font> 
   /p> 
  /AlternatingItemTemplate> 
  /asp:Repeater> 

顯示效果如下,結(jié)構(gòu)只顯示2、4、6、9列,這就是所謂的交叉顯示。

最后,我將五個模板一塊使用,前臺代碼如下

asp:Repeater ID="Repeater1" runat="server"> 
  HeaderTemplate> 
   h3 align="center">頁眉模板/h3> 
  /HeaderTemplate> 
 
  ItemTemplate> 
   p align="center"> 
   font color="blue"> %# DataBinder.Eval(Container.DataItem,"pID") %> 
   %# DataBinder.Eval(Container.DataItem,"personName") %> 
   %# DataBinder.Eval(Container.DataItem,"personSex") %>/font> 
   /p> 
  /ItemTemplate> 
  AlternatingItemTemplate> 
   p align="center"> 
   font color="blue"> %# DataBinder.Eval(Container.DataItem,"pID") %> 
   %# DataBinder.Eval(Container.DataItem,"personName") %> 
   %# DataBinder.Eval(Container.DataItem,"personSex") %>/font> 
   /p> 
  /AlternatingItemTemplate> 
 
  SeparatorTemplate> 
   hr color="red" size="1" /> 
  /SeparatorTemplate> 
 
  FooterTemplate> 
   h3 align="center">頁腳模板/h3> 
  /FooterTemplate> 
 
  /asp:Repeater> 

    顯示效果圖如下

      這就是利用控件將后臺數(shù)據(jù)庫中的信息用瀏覽器顯示出來的方法,其實不光Repeater控件,像DataList,GridView,CheckBoxList、DropDownList等等都能將數(shù)據(jù)庫中的信息加以綁定然后再在瀏覽器中顯示出來,希望對這幾個重要的控件可以熟練掌握。

您可能感興趣的文章:
  • 淺談ASP.NET常用數(shù)據(jù)綁定控件優(yōu)劣總結(jié)
  • 詳解ASP.NET數(shù)據(jù)綁定操作中Repeater控件的用法
  • 總結(jié)Visual Studio下ASP.NET模板化控件中的數(shù)據(jù)綁定
  • ASP.NET數(shù)據(jù)綁定GridView控件使用技巧
  • ASP.NET數(shù)據(jù)綁定之GridView控件
  • ASP.NET數(shù)據(jù)綁定之DataList控件實戰(zhàn)篇
  • ASP.NET數(shù)據(jù)綁定之DataList控件
  • AspNetAjaxPager,Asp.Net通用無刷新Ajax分頁控件,支持多樣式多數(shù)據(jù)綁定
  • ASP.NET數(shù)據(jù)綁定控件詳解

標(biāo)簽:吉林 婁底 麗江 宜春 本溪 重慶 汕頭 河南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET數(shù)據(jù)綁定之Repeater控件》,本文關(guān)鍵詞  ASP.NET,數(shù)據(jù),綁定,之,Repeater,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP.NET數(shù)據(jù)綁定之Repeater控件》相關(guān)的同類信息!
  • 本頁收集關(guān)于ASP.NET數(shù)據(jù)綁定之Repeater控件的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    福建省| 防城港市| 安平县| 右玉县| 宜宾县| 达孜县| 高安市| 衡东县| 苏尼特左旗| 卢氏县| 寻乌县| 沂水县| 阿巴嘎旗| 理塘县| 通榆县| 微博| 乐都县| 汉川市| 山丹县| 余江县| 蒙城县| 建宁县| 秭归县| 庐江县| 海宁市| 易门县| 虎林市| 南昌市| 新津县| 康保县| 岑溪市| 万州区| 大兴区| 罗山县| 师宗县| 宁海县| 芮城县| 墨竹工卡县| 望江县| 科尔| 余姚市|