Click here to Skip to main content
15,891,529 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: How to float text around an Image? Pin
Guffa28-Jan-07 19:32
Guffa28-Jan-07 19:32 
GeneralRe: How to float text around an Image? Pin
pnslcs29-Jan-07 1:58
pnslcs29-Jan-07 1:58 
Questionfiltering of html text tags Pin
sudidelaravindra28-Jan-07 0:08
sudidelaravindra28-Jan-07 0:08 
GeneralWhat tags? Pin
Guffa28-Jan-07 0:19
Guffa28-Jan-07 0:19 
Question3 Tier methodology in ASP>net Pin
Chwins27-Jan-07 19:51
Chwins27-Jan-07 19:51 
AnswerRe: 3 Tier methodology in ASP>net Pin
Bassam Saoud27-Jan-07 21:47
Bassam Saoud27-Jan-07 21:47 
AnswerRe: 3 Tier methodology in ASP>net Pin
Christian Graus28-Jan-07 10:00
protectorChristian Graus28-Jan-07 10:00 
QuestionExpand TreeView when redirect Pin
simsen27-Jan-07 7:40
simsen27-Jan-07 7:40 
Hi,

I have made a treeview, wich expand, when I remove the code:

root.NavigateUrl = "Default.aspx?id=" + ParentNode[loop, 0];

BUT I have to know, what Id (which node in the treeview the user select), to give the right input from the database.

I have stroggeld with this issue in many days now, but I still don't know what I shall do, so that when I redirect to Default, that it expand the treeview on that node, the user selected. Please can anybody help me?

My Code:
<br />
using System;<br />
using System.Data;<br />
using System.Configuration;<br />
using System.Web;<br />
using System.Web.Security;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
using System.Web.UI.HtmlControls;<br />
using System.Data.OleDb;<br />
<br />
public partial class _Default : System.Web.UI.Page <br />
{<br />
    private OleDbConnection connection = null;<br />
    public OleDbCommand command = null;<br />
    public string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Inetpub\\wwwroot\\Test\\Menu3\\menu.mdb;";<br />
<br />
    protected void Page_Load(object sender, EventArgs e)<br />
    {<br />
        if (!IsPostBack)<br />
        {<br />
            fill_Tree();<br />
        }<br />
    }<br />
<br />
    void fill_Tree()<br />
    {<br />
        /*<br />
        * Fill the treeview control Root Nodes From Parent Table<br />
        * and child nodes from ChildTables<br />
        */<br />
        connection = new OleDbConnection(connectionString); <br />
        connection.Open();<br />
<br />
        /*<br />
        * Query the database<br />
        */<br />
        command = new OleDbCommand();<br />
        command.Connection = connection;<br />
<br />
        DataTable myDataTable = new DataTable();<br />
        myDataTable.Columns.Add(new DataColumn("CategoryID", Type.GetType("System.String")));<br />
        myDataTable.Columns.Add(new DataColumn("ParentCategoryID", Type.GetType("System.String")));<br />
        myDataTable.Columns.Add(new DataColumn("CategoryName", Type.GetType("System.String")));<br />
        command.CommandText = "SELECT * FROM CATEGORIES WHERE ParentCategoryID = 0";<br />
<br />
        command.Parameters.Clear();<br />
<br />
        /*<br />
        *Define and Populate the SQL DataReader<br />
        */<br />
        OleDbDataReader myReader = command.ExecuteReader();<br />
        <br />
        /*<br />
        * Dispose the SQL Command to release resources<br />
        */<br />
        command.Dispose();<br />
<br />
        /*<br />
        * Initialize the string ParentNode.<br />
        * We are going to populate this string array with our            ParentTable Records<br />
        * and then we will use this string array to populate our TreeView1 Control with parent records<br />
        */<br />
<br />
        string[,] ParentNode = new string[100, 2];<br />
<br />
        /*<br />
        * Initialize an int variable from string array index<br />
        */<br />
<br />
        int count = 0;<br />
<br />
        /*<br />
        * Now populate the string array using our SQL Datareader Sdr.<br />
        */<br />
        while (myReader.Read())<br />
        {<br />
            ParentNode[count, 0] = myReader.GetValue(myReader.GetOrdinal("CategoryID")).ToString();<br />
            ParentNode[count++, 1] = myReader.GetValue(myReader.GetOrdinal("CategoryName")).ToString();<br />
        }<br />
<br />
        /*<br />
        * Close the SQL datareader to release resources<br />
        */<br />
        //myReader.Close();<br />
<br />
        /*<br />
        * Now once the array is filled with [Parentid,ParentName]<br />
        * start a loop to find its child module.<br />
        * We will use the same [count] variable to loop through ChildTable<br />
        * to find out the number of child associated with ParentTable.<br />
        */<br />
        for (int loop = 0; loop < count; loop++)<br />
        {<br />
            /*<br />
            * First create a TreeView1 node with ParentName and than<br />
            * add ChildName to that node<br />
            */<br />
            TreeNode root = new TreeNode();<br />
            root.Text = ParentNode[loop, 1];<br />
            root.PopulateOnDemand = false;<br />
            root.SelectAction = TreeNodeSelectAction.SelectExpand;<br />
<br />
            //root.Target = "_self";<br />
<br />
            /*<br />
            * Give the url of your page<br />
            */<br />
            root.NavigateUrl = "Default.aspx?id=" + ParentNode[loop, 0];<br />
<br />
            myReader.Close();<br />
<br />
            /*<br />
            * Now that we have [ParentId] in our array we can find out child modules<br />
            */<br />
            OleDbCommand Module_SqlCmd = new OleDbCommand("Select * from CATEGORIES where ParentCategoryID =" + ParentNode[loop, 0], connection);<br />
<br />
            OleDbDataReader Module_Sdr = Module_SqlCmd.ExecuteReader();<br />
<br />
            while (Module_Sdr.Read())<br />
            {<br />
                // Add children module to the root node<br />
<br />
                TreeNode child = new TreeNode();<br />
<br />
                child.Text = Module_Sdr.GetValue(Module_Sdr.GetOrdinal("CategoryName")).ToString();<br />
<br />
                child.Target = "_blank";<br />
<br />
                child.NavigateUrl = "your_page_Url.aspx";<br />
<br />
                root.ChildNodes.Add(child);<br />
            }<br />
<br />
            Module_Sdr.Close();<br />
<br />
            // Add root node to TreeView<br />
            TreeView1.Nodes.Add(root);<br />
            <br />
        }<br />
<br />
        /*<br />
        * By Default, when you populate TreeView Control programmatically, it expends all nodes.<br />
        */<br />
        TreeView1.CollapseAll();<br />
        connection.Close();<br />
<br />
    }<br />
<br />
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)<br />
    {<br />
        TreeView1.CollapseAll();<br />
        ExpandNodes(TreeView1.SelectedNode.ValuePath);<br />
    }<br />
<br />
    private void ExpandNodes(string valuepath)<br />
    {<br />
        string[] tmp = valuepath.Split('/');<br />
        string tmpValuePath = string.Empty;<br />
        foreach (string s in tmp)<br />
        {<br />
            tmpValuePath += s;<br />
            TreeView1.FindNode(tmpValuePath).Expand();<br />
            tmpValuePath += "/";<br />
<br />
        }<br />
    }<br />
}<br />

Kind regards,

simsen Smile | :)
AnswerRe: Expand TreeView when redirect Pin
Parwej Ahamad27-Jan-07 7:50
professionalParwej Ahamad27-Jan-07 7:50 
GeneralRe: Expand TreeView when redirect Pin
simsen27-Jan-07 7:55
simsen27-Jan-07 7:55 
GeneralRe: Expand TreeView when redirect Pin
Parwej Ahamad27-Jan-07 8:03
professionalParwej Ahamad27-Jan-07 8:03 
GeneralRe: Expand TreeView when redirect Pin
simsen27-Jan-07 12:51
simsen27-Jan-07 12:51 
Questionunable to run asp.net web application on Windows XP home edition Pin
reddyamar_uk27-Jan-07 5:03
reddyamar_uk27-Jan-07 5:03 
AnswerRe: unable to run asp.net web application on Windows XP home edition Pin
Parwej Ahamad27-Jan-07 7:36
professionalParwej Ahamad27-Jan-07 7:36 
GeneralRe: unable to run asp.net web application on Windows XP home edition Pin
reddyamar_uk27-Jan-07 12:30
reddyamar_uk27-Jan-07 12:30 
GeneralRe: unable to run asp.net web application on Windows XP home edition Pin
Parwej Ahamad28-Jan-07 1:29
professionalParwej Ahamad28-Jan-07 1:29 
GeneralRe: unable to run asp.net web application on Windows XP home edition Pin
reddyamar_uk28-Jan-07 22:20
reddyamar_uk28-Jan-07 22:20 
GeneralRe: unable to run asp.net web application on Windows XP home edition Pin
Sylvester george29-Jan-07 0:57
Sylvester george29-Jan-07 0:57 
QuestionDropdown first Item Pin
nour12327-Jan-07 5:03
nour12327-Jan-07 5:03 
AnswerRe: Dropdown first Item Pin
Guffa27-Jan-07 6:24
Guffa27-Jan-07 6:24 
GeneralRe: Dropdown first Item Pin
nour12327-Jan-07 19:27
nour12327-Jan-07 19:27 
GeneralRe: Dropdown first Item Pin
payback27-Jan-07 21:34
payback27-Jan-07 21:34 
GeneralRe: Dropdown first Item Pin
nour12327-Jan-07 22:14
nour12327-Jan-07 22:14 
QuestionHow to show different html files dynamically Pin
Haroon Sarwar27-Jan-07 4:20
Haroon Sarwar27-Jan-07 4:20 
AnswerRe: How to show different html files dynamically Pin
Guffa27-Jan-07 7:01
Guffa27-Jan-07 7:01 

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.