Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to generate multi level jquery menu dynamically but it display only one parent node and it's sub node but other parent and it's sub node are not displayed.

here i given my code

public partial class DynamicMenuitem : System.Web.UI.Page
{
DataSet objDs = new DataSet();
Curriculum objCurriculum = new Curriculum();
int intSchoolID;
int intCurriculumID;
int i, parentid;
String parentname;

protected void Page_Load(object sender, EventArgs e)
{
intSchoolID = 1;

try
{
if (!IsPostBack)
{
PopulateRootLevel(0, 1);
}

}
catch (Exception ex)
{ }
}

private void PopulateRootLevel(int curriculumID, int SchoolID)
{
try
{

objDs = objCurriculum.GetCurriculumParentBySchoolID(curriculumID, 1);
for (i = 0; i <= objDs.Tables[0].Rows.Count - 1; i++)
{

intCurriculumID = Convert.ToInt32(objDs.Tables[0].Rows[i]["CurriculumID"]);
parentname = objDs.Tables[0].Rows[i]["CurriculumName"].ToString();
Label lblrootlist = new Label();
int NoofChild = Convert.ToInt32(objDs.Tables[0].Rows[i]["childnodecount"].ToString());

if (NoofChild != 0)
{
Label lblrootsub = new Label();
lblrootsub.Text = "
  •      " + parentname + "
  • ";
    DataTable dt = (objDs).Tables[0];
    PlaceHolder1.Controls.Add(lblrootsub);
    PopulateLevel(dt, intCurriculumID);
    Label lblsubroot = new Label();
    lblsubroot.Text = "";
    PlaceHolder1.Controls.Add(lblsubroot);

    }
    else
    {
    lblrootlist.Text = "
  •      " + parentname + "
  • ";
    PlaceHolder1.Controls.Add(lblrootlist);
    }
    }
    }
    catch (Exception ex)
    { }
    }


    private void PopulateLevel(DataTable dt, int intCurriculumID)
    {
    try
    {
    DataTable dt1 = (objCurriculum.GetCurriculumParentBySchoolID(intCurriculumID, 1)).Tables[0];
    if (dt1.Rows.Count > 0)
    {
    Label sublevelulclose = new Label();
    Label sublevelul1 = new Label();
    sublevelul1.Text = "
      ";
      PlaceHolder1.Controls.Add(sublevelul1);
      foreach (DataRow dr in dt1.Rows)
      {
      String id;
      id = dr["CurriculumID"].ToString();
      parentname = dr["CurriculumName"].ToString();
      int NoofChild = Convert.ToInt32(dr["childnodecount"].ToString());

      if (NoofChild != 0)
      {
      Label sublevelli1 = new Label();
      sublevelli1.Text = "
    •      " + parentname + "
    • ";

      PlaceHolder1.Controls.Add(sublevelli1);
      Label sublevelul2 = new Label();
      sublevelul2.Text = "
        ";
        PlaceHolder1.Controls.Add(sublevelul2);

        PopulateRootLevel(Convert.ToInt32(id), 1);

        Label sublevelulclose2 = new Label();
        sublevelulclose2.Text = "
      ";
      PlaceHolder1.Controls.Add(sublevelulclose2);
      }
      else
      {
      Label subrootlevelli = new Label();
      subrootlevelli.Text = "
    •      " + dr["CurriculumName"].ToString() + "
    • ";
      PlaceHolder1.Controls.Add(subrootlevelli);
      }
      }

      sublevelulclose.Text = "
    ";
    PlaceHolder1.Controls.Add(sublevelulclose);

    }

    }
    catch (Exception ex)
    { }
    }
    }
    Posted
    Comments
    pietvredeveld 12-Apr-12 17:43pm    
    Where is de jquery code. This is ASP.Net isn't it. please add the javascript in you're question.

    Piet
    Sergey Alexandrovich Kryukov 12-Apr-12 21:16pm    
    How is this related to jQuery?.. :-)
    --SA

    1 solution

    When you post code please use the code brackets to keep the code fdzcz ld.

    They are the <pre> .. you code .. <\pre> commands.
     
    Share this answer
     
    Comments
    Nelek 14-Apr-12 8:38am    
    You should use the "have a question or comment" instead of giving void answers

    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