Make a record, save the time for future use, and find the one you previously wrote.CodeAnd I found some errors in the previously written code, but when the level reaches three or more layers, I can see where the error is. below is the corrected code:
Code // Bind administrative region drop-down list
Private Void Bindareaddl ()
{
DDL administrative region. Items. Clear ();
DDL administrative region. Items. insert ( 0 , New Listitem ( "" , " 0 " ));
Dataset DS = New S_area2dao (). getlist ( "" );
If (Ds. Tables. Count > 0 )
{
VaR query1 = DS. Tables [ 0 ]. Asenumerable (). Where (x => X [ " Parentid " ]. Tostring () = " 0 " );
Foreach (VAR item In Query1)
{
Listitem Li = New Listitem (item [ " Name " ]. Tostring (), item [ " ID " ]. Tostring ());
DDL administrative region. Items. Add (LI );
Int Index = 1 ;
Addchildlistitem (DS, item [ " ID " ]. Tostring (), index );
}
}
}
// Recursively add subitem
Private Void Addchildlistitem (Dataset ds, String PID, Int Index)
{
Int TMP = Index; // Save level
// Calculate the leading Blank
String Space_str = "" ;
For ( Int I = 0 ; I < Index; I ++ )
{
Space_str + = " ... " ;
}
VaR query1 = DS. Tables [ 0 ]. Asenumerable (). Where (x => X [ " Parentid " ]. Tostring () = PID );
Foreach (VAR item In Query1)
{
Listitem Li = New Listitem (space_str + Item [ " Name " ]. Tostring (), item [ " ID " ]. Tostring ());
DDL administrative region. Items. Add (LI );
Index ++ ;
Addchildlistitem (DS, item [ " ID " ]. Tostring (), index );
Index = TMP; // Restore level
}
}