Click here to Skip to main content
14,585,369 members
   

ASP.NET

 
AnswerRe: Ip Address Pin
Christian Graus15-Sep-09 21:49
mveChristian Graus15-Sep-09 21:49 
AnswerRe: Ip Address Pin
Manas Bhardwaj15-Sep-09 21:52
professionalManas Bhardwaj15-Sep-09 21:52 
QuestionAny possibility to avoid cache in asp.net Pin
anushh15-Sep-09 21:18
Memberanushh15-Sep-09 21:18 
AnswerRe: Any possibility to avoid cache in asp.net Pin
Christian Graus15-Sep-09 21:25
mveChristian Graus15-Sep-09 21:25 
GeneralRe: Any possibility to avoid cache in asp.net Pin
anushh15-Sep-09 21:46
Memberanushh15-Sep-09 21:46 
GeneralRe: Any possibility to avoid cache in asp.net Pin
Christian Graus15-Sep-09 21:50
mveChristian Graus15-Sep-09 21:50 
GeneralRe: Any possibility to avoid cache in asp.net Pin
N a v a n e e t h15-Sep-09 22:13
MemberN a v a n e e t h15-Sep-09 22:13 
AnswerRe: Any possibility to avoid cache in asp.net Pin
Abhishek Sur15-Sep-09 21:45
professionalAbhishek Sur15-Sep-09 21:45 
GeneralRe: Any possibility to avoid cache in asp.net Pin
anushh15-Sep-09 21:48
Memberanushh15-Sep-09 21:48 
GeneralRe: Any possibility to avoid cache in asp.net Pin
Abhishek Sur15-Sep-09 22:03
professionalAbhishek Sur15-Sep-09 22:03 
QuestionJavascript validation in asp.net for a textbox and dropdown Pin
rummer15-Sep-09 20:42
Memberrummer15-Sep-09 20:42 
AnswerRe: Javascript validation in asp.net for a textbox and dropdown Pin
Vimalsoft(Pty) Ltd15-Sep-09 20:48
professionalVimalsoft(Pty) Ltd15-Sep-09 20:48 
AnswerRe: Javascript validation in asp.net for a textbox and dropdown Pin
Christian Graus15-Sep-09 21:15
mveChristian Graus15-Sep-09 21:15 
AnswerRe: Javascript validation in asp.net for a textbox and dropdown Pin
Abhishek Sur15-Sep-09 21:52
professionalAbhishek Sur15-Sep-09 21:52 
GeneralRe: Javascript validation in asp.net for a textbox and dropdown Pin
Christian Graus15-Sep-09 21:57
mveChristian Graus15-Sep-09 21:57 
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 

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.