【ASP.Net】什麼!Repeater裡面還有個Repeater?!

來源:互聯網
上載者:User

標籤:style   blog   http   ar   sp   資料   div   on   log   

我就貼核心代碼,這個項目因為我正在幫人家做,所以暫時不能公開太多源碼
 
(如果真想要源碼的話,等我10月底幫他把項目提升到三層時再公開現在這1.0版本的源碼吧~)

 

 先說下我的目的:根據Repeter1中的id,巢狀查詢Repeter內部的值(沒辦法,我資料庫就是用三層設計的,所以代碼就。。。)
 
 直接貼核心源碼(其實代碼多了反而幹擾視線)
  1.先給Repeater1註冊Repeater1_ItemDataBound 事件 <asp:Repeater ID="Repeater1" runat="server"  OnItemDataBound="Repeater1_ItemDataBound"> <ItemTemplate>    .............        <asp:TextBox ID="Tbl_SayId" runat="server" Text=‘<%#Eval("Tbl_SayId") %>‘ Visible="False"></asp:TextBox>    ..............        <asp:Repeater ID="Repeater2" runat="server">        <ItemTemplate>        ...............        </ItemTemplate>        <AlternatingItemTemplate>        ...............        </AlternatingItemTemplate>        </asp:Repeater>    </ItemTemplate> </asp:Repeater> 
想下目的?TextBox我來幹什麼的?~思考下。。。~~~~(隱藏,為了後面的或值)

        如果在後台中直接存取肯定訪問不到Repeater2,必須通過Repeater1來間接訪問才行,而且用配置ObjectDataSource的方法也行不通(我控制項用的不是很熟),所以對於Repeater2我就手敲代碼了,下面看看後台代碼:
  protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)    {        Repeater r2 = (Repeater)e.Item.FindControl("Repeater2"); //擷取到Repeater2        TextBox txtid = (TextBox)e.Item.FindControl("Tbl_SayId"); //擷取到你需要的值        DataTable dt = Say.GetReSays(txtid.Text); //根據你的值查詢,然後把結果返回(Say是我定義的一個臨時工具類)        r2.DataSource = dt; //制定Repeater2的資料來源        r2.DataBind(); //綁定一下    }簡單吧~其實不想透的話還是很浪費時間的。。。獻上妹子一枚,放鬆下心情~哈哈哈,閃~  


 
 

學校網速太垃圾了。。。我都想走讀了

 

【ASP.Net】什麼!Repeater裡面還有個Repeater?!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.