Today, we use a drop-down box Binding. It's easy to display hierarchical relationships. It's the first blog!
/// <Summary>
/// Bind the drop-down list
/// </Summary>
/// <Param name = "dt"> bound data source </param>
/// <Param name = "parentId"> id of the upper level </param>
/// <Param name = "colId"> value name </param>
/// <Param name = "colName"> text name </param>
/// <Param name = "drs"> upper-level record set </param>
/// <Param name = "ddl"> drop-down list </param>
/// <Param name = "leveStr"> hierarchical prefix </param>
/// <Param name = "nextStr"> prefix of a hierarchical prefix </param>
Protected void GetChild (DataTable dt, string parentId, string colId, string colName, DataRow [] drs, DropDownList ddl, string leveStr, string nextStr)
{
Foreach (DataRow dr in drs)
{
String txt = dr [colName]. ToString ();
If (leveStr. Length! = 1)
{
Txt = leveStr + dr [colName]. ToString ();
}
Ddl. Items. Add (new ListItem (txt, dr [colId]. ToString ()));
DataRow [] cdrs = dt. Select (parentId + "= '" + dr [colId] + "'", colId + "asc ");
If (cdrs. Length! = 0)
{
String nextLevelStr = leveStr. Insert (0, nextStr );
GetChild (dt, parentId, colId, colName, cdrs, ddl, nextLevelStr, nextStr );
}
}
}
Drs is queried through dt. select ("condition.
From Ne