The nested datalist control in the repeart control usually displays data. datalist is preferred on webpages because it is flexible and has good style control. some specific functions need to be bound between data controls. but what if I bind another datalist in datalist? This efficiency is very low. When the functional conditions permit, repert should be given priority to datalist nesting.
Below isExample of nested datalist control in the repeart Control
Test. aspx
- <% # Databinder. eval (container. dataitem, "name") %>
- <% # Databinder. eval (container. dataitem, "title") %>
Test. aspx. CS
Protected void page_load (Object sender, eventargs E)
{
String SQL = "select * From nvwa_type order by ID ";
String connstring = "provider = Microsoft. Jet. oledb.4.0; Data Source =" + server. mappath ("~ /App_data/mydate. mdb ");
Oledbdataadapter ODA = new oledbdataadapter (SQL, connstring );
Dataset DS = new dataset ();
ODA. Fill (DS );
This. repeater1.datasource = Ds;
This. repeater1.databind ();
}
Protected void repeaterincluitemdatabound (Object sender, repeateritemeventargs E)
{
If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
{
String connstring = "provider = Microsoft. Jet. oledb.4.0; Data Source =" + server. mappath ("~ /App_data/mydate. mdb ");
Int type_id = convert. toint32 (datarowview) E. Item. dataitem). Row ["ID"]. tostring ());
Datalist DL = (datalist) E. Item. findcontrol ("datalist1"); // locate the datalist1 Control
If (type_id! = 0 & type_id! = NULL)
{
String SQL _p = "select * From nvwa_product where type =" + type_id + "order by ID ";
Oledbdataadapter ODA = new oledbdataadapter (SQL _p, connstring );
Dataset DS = new dataset ();
ODA. Fill (DS );
DL. datasource = Ds;
DL. databind ();
}
}
}