asp.net implementation of DataList and Repeater nested Binding method _ practical skills

Source: Internet
Author: User

The example in this article describes the method by which ASP.net implements DataList and repeater nested bindings. Share to everyone for your reference, specific as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "Home.aspx.cs" inherits= "Home"%> <body> <form ID = "Form1" runat= "Server" > <asp:datalist id= "monitortypelist" runat= "Server" repeatcolumns= "4" Onitem Databound= "Monitortypelist_itemdatabound" repeatdirection= "horizontal" itemstyle-verticalalign= "Top" > < itemtemplate> <table class= "Conbox" width= "186" border= "0" cellpadding= "0" cellspacing= "1" style= "Margin-rig ht:10px; " > <tr> <th><a href= "<% #Eval (" Plugpath ")%>" ><% #Eval ("Monitor_type_name")
          %></a></th> </tr> <asp:repeater id= "monitorconfiglist" runat= "Server" > <ItemTemplate> <tr> <td><a href= "<% #Eval (" Plugpath ")%>?monitor_id=<% #Eval ("monitor_id")%> "><% #Eval (" Monitor_name ")%></a></td> </tr> </it
      Emtemplate>   </asp:Repeater> </table> </ItemTemplate> </asp:DataList> </form> &L

 T;/body>

Home.aspx.cs

Using System;
Using System.Collections;
Using System.Configuration;
Using System.Data;
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; Public partial class Home:System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {mycheck.is
    Loginnonreturn (); if (!
    IsPostBack) {bind_monitortypelist (); } protected void Bind_monitortypelist () {String sql = ' Select Monitor_type_id,monitor_type_name from Monitor_
    Type ";
    Dbconn conn = new Dbconn (); DataSet ds = conn.
    DataSet (SQL, "Monitor_type"); Monitortypelist.datasource = ds.
    Tables[0];
    Monitortypelist.databind (); Ds.
    Dispose (); Conn.
  Close (); } protected void Monitortypelist_itemdatabound (object sender, DataListItemEventArgs e) {if (E.item.itemtype = = Li Stitemtype.item | | E.item.itemtype = = ListiTemtype.alternatingitem) {String monitor_type_id = (DataRowView) e.item.dataitem). row["monitor_type_id"].
      ToString ();
      Repeater monitorconfiglist = (Repeater) e.item.findcontrol ("Monitorconfiglist"); if (monitorconfiglist!= null) {String sql = "Select Monitor_id,nonitor_name,plugpath from Monitor where mo
        Nitor_type_id= "+ monitor_type_id;
        Dbconn conn = new Dbconn (); DataSet ds = conn.
        DataSet (SQL, "Monitor"); Monitorconfiglist.datasource = ds.
        Tables[0];
        Monitorconfiglist.databind (); Ds.
        Dispose (); Conn.
      Close ();

 }
    }
  }
}

More interested in asp.net related content readers can view the site topics: "asp.net file Operation skills Summary", "ASP.net ajax Skills Summary" and "asp.net cache operation skills Summary."

I hope this article will help you to ASP.net program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.