欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
用戶(hù)控件和服務(wù)器控件的數據綁定

一、綁定Repeater控件的數據源

aspx.cs文件中綁定Repeater控件的數據源在BindDataSource()中:
protected override void BindDataSource()
{
   this.rpID.DataSource = this.dataList;
   this.rpID.DataBind();
}
Repeater控件事件OnItemDataBound,表示在循環(huán)加載<ItemTemplate>列表時(shí)候,會(huì )對每一項Item進(jìn)行具體的操作。
例子:
  Protected void rp_ItemDataBound(object sender,RepeaterItemEventArgs e)
  {
      if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
      {
          List<Info> Infos = this.rpID.DataSource as List<Info>;
         
          Info info = e.Item.DataItem as Info;
          Literal lt = e.Item.FindControl("lt") as Literal;
          lt.Text = Info.Title;
      }
  }
可以看出來(lái)對于Repeater控件中的<ItemTemplate>里面的用戶(hù)控件、服務(wù)器控件的賦值是在Repeater控件事件OnItemDataBound中進(jìn)行的。
二、用戶(hù)控件
用戶(hù)控件T.ascx代碼有:
字段:
private string title;
屬性:
public string Title
{
    get
    {
       return this.title;
    }
}
方法:
SetTitle()
{
    this.title = "Hello world!";
}
其實(shí)這里的字段賦值也是可以用屬性進(jìn)行賦值的,不過(guò)要在屬性聲明中加上set部分。
那么這個(gè)T的用戶(hù)控件的要是在Repeater控件中的<ItemTemplate>里面出現的話(huà),是要在
Repeater控件事件OnItemDataBound里面進(jìn)行具體的賦值的。
例子:
  Protected void rp_ItemDataBound(object sender,RepeaterItemEventArgs e)
  {
      if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
      {
          List<Info> Infos = this.rpID.DataSource as List<Info>;
         
          Info info = e.Item.DataItem as Info;
          T t = e.Item.FindControl("t") as T;
          t.SetTitle(info.Title);
      }
  }
可以看到上面的操作已經(jīng)把數據存到title字段里面了,在用戶(hù)空間的T.ascx代碼中用<%=Title%>來(lái)訪(fǎng)問(wèn)Title屬性,
因為之前已經(jīng)聲明了Title屬性的get部分。
三、一個(gè)簡(jiǎn)單的Reapter控件的使用全貌
在aspx頁(yè)面中:
<asp:Repeater ID="rpID" runat="server" OnItemDataBound="rp_ItemDataBound">
    <ItemTemplate>
        <asp:Literal ID="lt" runat="server"></asp:Literal>
    </ItemTemplate>
</asp:Repeater>
在aspx.cs頁(yè)面中:
protected override void BindDataSource()
{
   this.rpID.DataSource = this.dataList;
   this.rpID.DataBind();
}
  Protected void rp_ItemDataBound(object sender,RepeaterItemEventArgs e)
  {
      if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
      {
          List<Info> Infos = this.rpID.DataSource as List<Info>;
         
          Info info = e.Item.DataItem as Info;
          Literal lt = e.Item.FindControl("lt") as Literal;
          lt.Text = Info.Title;
      }
  }
注意我前面已經(jīng)提到了服務(wù)器控件和用戶(hù)控件在這里面的使用方式其實(shí)是一摸一樣的。
可以看出來(lái)BindDataSource()是對aspx頁(yè)面中最外層的用戶(hù)控件、服務(wù)器控件的數據源進(jìn)行綁定,
而OnItemDataBound事件是對Repeater控件中的<ItemTemplate>里面的用戶(hù)控件、服務(wù)器控件的數據源
進(jìn)行綁定。
四、在Repeater控件中嵌套使用Repeater控件
這其實(shí)是一個(gè)特例:
在aspx頁(yè)面中:
<asp:Repeater ID="rpID" runat="server" OnItemDataBound="rp_ItemDataBound">
    <ItemTemplate>
        <asp:Repeater ID="rp_rpID" runat="server">
            <asp:Literal ID="lt" runat="server"></asp:Literal>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>
在aspx.cs頁(yè)面中:
protected override void BindDataSource()
{
   this.rpID.DataSource = this.dataList;
   this.rpID.DataBind();
}
  Protected void rp_ItemDataBound(object sender,RepeaterItemEventArgs e)
  {
      if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
      {
          List<Info> Infos = this.rpID.DataSource as List<Info>;
         
          Info info = e.Item.DataItem as Info;
          Repeater rp_rpID = e.Item.FindControl("rp_rpID") as Repeater;
          rp_rpID.DataSource = dataList;
          rp_rpID.DataBind();
      }
  }
 
五、一般用戶(hù)控件的賦值情況
在aspx頁(yè)面中:
<UCCommon:T ID="UCT" runat="server" />
在aspx.cs頁(yè)面中:
protected override void BindDataSource()
{
   this.UCT.ItemList = dataList;
   this.UCT.Title = "hello world!";
}
是在給用戶(hù)控件的屬性賦值。
用戶(hù)控件隱藏文件T.ascx.cs代碼有:
字段:
private List<Info> itemList;
private string title;
屬性:
public string Title
{
    set
    {
       this.title = value;
    }
}
public List<Info> ItemList
{
    set
    {
       this.itemList = value;
    }
}
這里面就是用戶(hù)控件定義了屬性對字段進(jìn)行賦值的。
如果用戶(hù)控件中還有用戶(hù)控件的賦值情況:
用戶(hù)控件隱藏文件T.ascx.cs代碼有:
protected override void BindDataSource()
{
   T_T.SelectList = dataList;
   T_T.Title = "hello world!";
}
這里和aspx頁(yè)面一樣是在BindDataSource()中對外層的用戶(hù)控件進(jìn)行賦值的。
當然T_T中會(huì )聲明相應的字段和屬性保存數據。
最后會(huì )在自己的BindDataSource()里面再次賦值給需要的控件,或者直接在頁(yè)面上顯示所得的數據。
可以在用戶(hù)控件的T.ascx代碼中直接獲取屬性例如:
<%= Title %>
在aspx頁(yè)面中Repeater控件中的<ItemTemplate>里面綁定數據:
<%#Eval("Detail") == null || Eval("Detail").ToString() == string.Empty ? " " : Eval("Detail")%>
<%#(Container.DataItem as BannerInfo).BannerTitle %>
在aspx頁(yè)面中Repeater控件中Repeater控件的<ItemTemplate>里面綁定數據:
<%#Container.DataItem == null || Container.DataItem.ToString()==string.Empty ? " " : Container.DataItem%>
在aspx頁(yè)面直接賦值和在用戶(hù)控件中一樣:
<%= Title %>
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
使用嵌套的Repeater控件顯示分級數據
關(guān)于A(yíng)SP.NET 數據綁定
一天精通asp.net:專(zhuān)為有其他語(yǔ)言基礎的人 (轉)
DataList利用PagedDataSource來(lái)進(jìn)行分頁(yè)!_蕭四郎
教你30秒打造強類(lèi)型ASP.NET數據綁定
四十六::DataList和Repeater里的自定義button
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久