Automatically obtains master-slave relationship data in the database. The following lists the cities that match the province and province, Code As follows:
< ASP: Repeater ID = "Repeater1" Runat = "Server" >
< Itemtemplate >
< Span Style = "Font-weight: bold" > <% #Eval("Pname") %> </ Span >
< Ul >
< ASP: Repeater ID = "Detal" Runat = "Server" Datasource = '<% # Getcity (eval ("PID"). tostring ()) % > '>
< Itemtemplate >
< Li > <% #Eval("City_name") %> </ Li >
</ Itemtemplate >
</ ASP: Repeater >
</ Ul >
</ Itemtemplate >
</ ASP: Repeater >
Important: datasource = '<% # getawd (eval ("PID"). tostring () %>' Call the getcity method to obtain the subclass.
Protected Void Page_load ( Object Sender, eventargs E)
{
If(!Page. ispostback)
Bindgrid ();
}
// Obtain a category
Protected Void Bindgrid ()
{
String Plain text = " Select PID, pname from Pro " ;
Datatable dt = VC. getdatatable (plain text );
Repeater1.datasource = DT;
Repeater1.databind ();
}
// Get small content
Protected Datatable getcity ( String ID)
{
String Plain text = " Select city_name from city where promo_id = " + ID + "" ;
Datatable dt = VC. getdatatable (plain text );
Return DT;
}
The implementation result is as follows:
Method 2: bind the second repeater to the itemdatabound event of the first repeater. The first repeater in HTML code is not assignedDatasource
Protected Void Repeattitle_itemdatabound ( Object Sender, repeateritemeventargs E)
{
Datarowview Dr = (Datarowview) E. Item. dataitem;
Datatable mydt = Getcity (Dr [ 0 ]. Tostring ());
If (Mydt. Rows. Count > 0 )
{
Repeater myrepeat = (Repeater) E. Item. findcontrol ( " Repeatcont " );
Myrepeat. datasource = Mydt;
Myrepeat. databind ();
Mydt. Dispose ();
}
Else
{
E. Item. Visible= False;//No data is displayed
}
}