Hi,
Je voudrais cree un IE TreeView avec ASP.NET en CSharp, jusqu'a present je suis arrive a faire apparaitre les parent and le enfant direct. Malheureusement, je n'arrive pas a exposer les enfants des enfants un si de suite...
Ci -dessous est la structure de mon database:
Index | Name | ParentIndex
1 | pierre | 0
2 | paul | 0
3 |jean | 1
4 | tele | 3
5 | papier |4 <---- j'ai des problem a exposer cette ---------------------------------information
public TreeNodeCollection populateTreeNode (string db, string tableName,Microsoft.Web.UI.WebControls.TreeNodeCollection nodes){
TreeNode child = null;
TreeNode par = null;
this.producePopulatedTableDS(db,tableName);
for ( int x=0; x < this.TREE_ARRAY.Count; x++) {
for (int y=0; y <((ArrayList)this.TREE_ARRAY[x]).Count; y++) {
par = (TreeNode)((ArrayList)this.TREE_ARRAY[x])[y]; //Array of Node
for (int z=0; z < ((ArrayList)this.TREE_ARRAY[y+1]).Count; z++) {
child = (TreeNode)((ArrayList)this.TREE_ARRAY[y+1])[z];
if( par.ID == child.ChildType) {
par.Nodes.Add(child);
}
}//third for
if( par.ID == child.ChildType){
nodes.Add (par); this.TREENODECOLLECTION = nodes;
}
}//second for
}//first
return this.TREENODECOLLECTION;
}//End populateTreeNode
public void producePopulatedTableDS (string db, string tableName)
{ DataTable dataTable = null;
dataTable = this.TableDataSet(db, tableName); this.TABLE = dataTable;
this.GET_CONNECTION.Open();
//OleDbDataReader aReader = this.SELECTED_CMD.ExecuteReader();
this.DISTINCT = this.distinct (tableName,"parent");
//Go through array of distinct number
this.TREE_ARRAY = new ArrayList ();
for (int x=0; x <this.DISTINCT.Count; x++) {
this.builtParentSet (distinctList,tableName,x);
}
int count = this.TREE_ARRAY.Count ;
this.GET_CONNECTION.Close();
}//End PPT
private ArrayList distinct (string tableName, string column)
{
ArrayList distinctAL = new ArrayList ();
//this.GET_CONNECTION.Open();
this.SELECTED_CMD.CommandText = "SELECT DISTINCT "+column+" FROM " +tableName;
aReader = this.SELECTED_CMD.ExecuteReader();
try
{
while(aReader.Read())
{
distinctAL.Add(aReader[column]);
}// End while
}
catch(OleDbException e)
{
this.GET_CONNECTION.Close();
Console.WriteLine("Error: {0}", e.Errors[0].Message);
}//End try
//close the reader
aReader.Close();
//close the connection Its important.
// aConnection.Close();
return distinctAL;
}//End distinct
private void builtParentSet (ArrayList distinctAL, string tableName, int x)
{
//ArrayList arrayLst = new ArrayList ();
DataStructDB dataStruct = null;
TreeNode parent = null;
this.SELECTED_CMD.CommandText = "SELECT * FROM " +tableName+ " WHERE parent ="+ Convert.ToInt32(distinctAL[x])+ " ORDER BY id";
aReader = this.SELECTED_CMD.ExecuteReader();
this.NODE = new ArrayList();
while(aReader.Read())
{
dataStruct = new DataStructDB ();
dataStruct.ID = (Int32) aReader["id"];
dataStruct.COMPANY = aReader["company"].ToString();
dataStruct.PARENT = (Int32) aReader["parent"];
//Populate the different array
parent = new TreeNode();
parent.Type = type;
parent.ID = dataStruct.ID.ToString() ;
parent.Text = dataStruct.COMPANY;
parent.ChildType = dataStruct.PARENT.ToString() ;
this.NODE.Add (parent);
}//End while
this.TREE_ARRAY.Add(this.NODE);
aReader.Close();
// return arrayLst;
}//End BuildParentSet