Click here to Skip to main content
14,580,662 members
   

ASP.NET

 
GeneralRe: Javascript validation in asp.net for a textbox and dropdown Pin
Abhishek Sur15-Sep-09 22:09
professionalAbhishek Sur15-Sep-09 22:09 
GeneralRe: Javascript validation in asp.net for a textbox and dropdown Pin
Christian Graus15-Sep-09 22:10
mveChristian Graus15-Sep-09 22:10 
GeneralRe: Javascript validation in asp.net for a textbox and dropdown Pin
Abhishek Sur15-Sep-09 22:43
professionalAbhishek Sur15-Sep-09 22:43 
AnswerRe: Javascript validation in asp.net for a textbox and dropdown Pin
Arun Jacob15-Sep-09 22:51
MemberArun Jacob15-Sep-09 22:51 
QuestionProblem in populating a treeview from database Pin
rinku soni 2315-Sep-09 20:23
Memberrinku soni 2315-Sep-09 20:23 
AnswerRe: Problem in populating a treeview from database Pin
Abhijit Jana15-Sep-09 20:27
professionalAbhijit Jana15-Sep-09 20:27 
AnswerRe: Problem in populating a treeview from database Pin
Christian Graus15-Sep-09 21:18
mveChristian Graus15-Sep-09 21:18 
AnswerRe: Problem in populating a treeview from database Pin
N a v a n e e t h15-Sep-09 22:08
MemberN a v a n e e t h15-Sep-09 22:08 
A tree is a basic data structure and everyone should know to work with that.

When you add a node, you need to find the parent of that node using the parent id. To do this, keep a reference to the root node and iterate recursively until you find the node with the parent id. New node should be added as a child of this node.

Above method has a O(n) complexity where n is the total number of nodes in a tree. An efficient approach will be to keep each node in an associative container with node id as key. When adding each item, look for a TreeNode object in this container. Here is a working code.
void PopulateTreeView(DataTable dt, TreeView tv)
{
    Dictionary<int, TreeNode> nodes = new Dictionary<int, TreeNode>();
    TreeNode root = null;
    foreach (DataRow row in dt.Rows)
    {
        int parentId = int.Parse(row["Parent_Id"].ToString());
        int nodeId = int.Parse(row["Node_Id"].ToString());
        string nodeName = row["Node_Name"].ToString();

        TreeNode node;
        if (nodes.TryGetValue(parentId, out node))
        {
            TreeNode newNode = new TreeNode(nodeName);
            nodes.Add(nodeId, newNode);
            node.ChildNodes.Add(newNode);
        }
        else
        {
            node = new TreeNode(nodeName);
            nodes.Add(nodeId, node);
            node.ChildNodes.Add(node);
            if (parentId == 0)
                root = node;
        }
    }
    tv.Nodes.Add(root);
}
Smile | :)


GeneralRe: Problem in populating a treeview from database Pin
Abhishek Sur15-Sep-09 22:11
professionalAbhishek Sur15-Sep-09 22:11 
GeneralRe: Problem in populating a treeview from database Pin
N a v a n e e t h15-Sep-09 22:14
MemberN a v a n e e t h15-Sep-09 22:14 
QuestionHow dynamic objects work during a post back Pin
compninja2515-Sep-09 14:58
Membercompninja2515-Sep-09 14:58 
AnswerRe: How dynamic objects work during a post back Pin
Christian Graus15-Sep-09 15:00
mveChristian Graus15-Sep-09 15:00 
GeneralRe: How dynamic objects work during a post back Pin
compninja2515-Sep-09 16:13
Membercompninja2515-Sep-09 16:13 
GeneralRe: How dynamic objects work during a post back Pin
N a v a n e e t h15-Sep-09 16:18
MemberN a v a n e e t h15-Sep-09 16:18 
GeneralRe: How dynamic objects work during a post back Pin
compninja2516-Sep-09 2:08
Membercompninja2516-Sep-09 2:08 
GeneralRe: How dynamic objects work during a post back Pin
Christian Graus15-Sep-09 16:19
mveChristian Graus15-Sep-09 16:19 
GeneralRe: How dynamic objects work during a post back Pin
Abhijit Jana15-Sep-09 18:26
professionalAbhijit Jana15-Sep-09 18:26 
AnswerRe: How dynamic objects work during a post back Pin
Arun Jacob15-Sep-09 18:58
MemberArun Jacob15-Sep-09 18:58 
GeneralRe: How dynamic objects work during a post back Pin
Abhijit Jana15-Sep-09 19:08
professionalAbhijit Jana15-Sep-09 19:08 
GeneralRe: How dynamic objects work during a post back Pin
r a m e s h15-Sep-09 20:39
Memberr a m e s h15-Sep-09 20:39 
GeneralRe: How dynamic objects work during a post back Pin
compninja2516-Sep-09 2:21
Membercompninja2516-Sep-09 2:21 
QuestionPassing Credentials from ASP.NET to OWA Pin
ahayw0115-Sep-09 12:51
Memberahayw0115-Sep-09 12:51 
AnswerRe: Passing Credentials from ASP.NET to OWA Pin
Not Active15-Sep-09 13:26
mentorNot Active15-Sep-09 13:26 
GeneralRe: Passing Credentials from ASP.NET to OWA Pin
Abhijit Jana15-Sep-09 18:31
professionalAbhijit Jana15-Sep-09 18:31 
GeneralRe: Passing Credentials from ASP.NET to OWA Pin
Not Active16-Sep-09 1:51
mentorNot Active16-Sep-09 1:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.