Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
    {
        

        SqlDataAdapter da = new SqlDataAdapter("Select Menu_id, Menu_name, Menu_url from Menu", con);

        DataTable dttc = new DataTable();

        da.Fill(dttc);

        HtmlGenericControl main = UList("Menuid", "menu");

        foreach (DataRow row in dttc.Rows)

        {

            da = new SqlDataAdapter("select MenuCatId,MenuCatagName,MenuCateg_url from Submenu where Menu_id=" + row["Menu_id"].ToString(), con);

            DataTable dtDist = new DataTable();

            da.Fill(dtDist);

            if (dtDist.Rows.Count > 0)

            {

                HtmlGenericControl sub_menu = LIList(row["Menu_name"].ToString(), row["Menu_id"].ToString(),  row["Menu_url"].ToString());               

                HtmlGenericControl ul = new HtmlGenericControl("ul");              

                foreach (DataRow r in dtDist.Rows)

                {

                    ul.Controls.Add(LIList(r["MenuCatagName"].ToString(), r["MenuCatId"].ToString(), r["MenuCateg_url"].ToString()));

                }

                sub_menu.Controls.Add(ul);

                main.Controls.Add(sub_menu);

            }

            else

            {

                main.Controls.Add(LIList(row["Menu_name"].ToString(), row["Menu_id"].ToString(), row["Menu_url"].ToString()));

            }

        }

        Panel1.Controls.Add(main);

    }

    private HtmlGenericControl UList(string id, string cssClass)

    {

        HtmlGenericControl ul = new HtmlGenericControl("ul");

        ul.ID = id;

        ul.Attributes.Add("class", cssClass);

        return ul;

    }

    private HtmlGenericControl LIList(string innerHtml, string rel, string url)

    {      

        HtmlGenericControl li = new HtmlGenericControl("li");

        li.Attributes.Add("rel", rel);

        li.InnerHtml = "<a href=" + string.Format(">" + innerHtml+"</a>";

        return li;

    }
    }
Posted
Updated 2-Apr-14 0:03am
v2
Comments
Pheonyx 2-Apr-14 4:14am    
This is an Awful question.
You "question" cuts off at the word "mem" (what ever that word is meant to be).
You have not used sensible formatting to make this readable.

Use the "Improve Question" feature to make this a better question.
Your initial single line question should be clear and concise, i.e. it should give a quick hint into what you are trying to do... for example "How do I create a fully editable and dynamic menu structure?".

Then the main body of your question should contain a detailed explanation of what you are trying to achieve (and if necessary why). And code snippets demonstrating what you have tried should be concise (not entire code dumps) and be formatted using the <pre></pre> tags (as the editor does for you if you use it properly).

Explain what is not working and where any errors occur and people are more likely to be able to help you.
What is the issue? What are you doing?
ZurdoDev 2-Apr-14 9:05am    
What's your question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900