版主,你给个例子吧.
我的后台代码是这样的.
str+=这部分是有问题的.我还没想好该怎么写比较.,用贴的方式不知道该怎么循环了.
public string getMenu()
{
string str = null;
int i = 0;
SqlConnection sqlcon = new SqlConnection(connectionString);
sqlcon.Open();
SqlDataAdapter sda = new SqlDataAdapter("select ID,parentID,text from topmenu where parentID=0
order by IsBoot", sqlcon);
DataSet ds = new DataSet();
sda.Fill(ds);
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
//MenuItem menunode = new MenuItem();
//menunode.Text = dr["text"].ToString();
//menunode.Value = dr["ID"].ToString();
//Menu1.Items.Add(menunode);
//getMenuchild(menunode, menunode.Value, Convert.ToInt32(dr["ID"]));
str += "{text:'" + ds.Tables[0].Rows[i]["text"].ToString() + "','topid':'" + i + "','colid':'" + i + "','value':'" + ds.Tables[0].Rows[i]["text"].ToString() + "','fun':function(){}},";
str += getMenuchild("mpmenu" + i, Convert.ToInt32(ds.Tables[0].Rows[i]["ID"].ToString()),i);
//str += " ";
//i++;
}
return str;
}
//public string getMenuchild(MenuItem node,string value ,int id)
public string getMenuchild(string strmenu, int id,int j)
{
string childstr = null;
int i = 0;
SqlConnection sqlcon = new SqlConnection(connectionString);
sqlcon.Open();
SqlDataAdapter sda = new SqlDataAdapter("select ID,parentID,text from topmenu where parentID='" + id + "'
order by IsBoot", sqlcon);
DataSet ds = new DataSet();
sda.Fill(ds);
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
//MenuItem menunode = new MenuItem();
//menunode.Text = dr["text"].ToString();
//menunode.Value = dr["ID"].ToString();
//node.ChildItems.Add(menunode);
childstr += "{text:'" + ds.Tables[0].Rows[i]["text"].ToString() + "','topid':'0','colid':'1','value':'" + ds.Tables[0].Rows[i]["text"].ToString() + "','fun':function(){}},";
//childstr += strmenu + ".mMenuAddItem(mpmenuchild" + i + ");";
childstr += getMenuchild("mpmenuchild" + i, Convert.ToInt32(ds.Tables[0].Rows[i]["ID"].ToString()),i);
}
return childstr;
}