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)
{ }
}
}