public string DataTableToJson()
{
string dataJson = "";
string temp = "";
string tempChildren = "";
int id = 0;
int idChildren = 0;
DataTable dt = GJPDbHelper.DAL.ExecuteDataSet("select distinct 品牌,类型 from dbo.AIRB_MMTREE where treeType='1'").Tables[0];
if (dt.Rows.Count > 0)
{
dataJson = "[";
foreach (System.Data.DataRow dr in dt.Rows)
{
if (temp == "" || temp != dr[0].ToString())
{
if (id == 0)
{
id++;
idChildren = 0;
idChildren++;
temp = dr[0].ToString();
tempChildren = dr[1].ToString();
dataJson = dataJson + "{"id":" + id + ","text":"" + dr[0] + "","children":[{"id":" + Convert.ToInt32(id.ToString()+idChildren.ToString()) + ","text":"" + dr[1] + ""}";
}
else
{
id++;
idChildren = 0;
idChildren++;
temp = dr[0].ToString();
tempChildren = dr[1].ToString();
dataJson = dataJson + "]},{"id":" + id + ","text":"" + dr[0] + "","children":[{"id":" + Convert.ToInt32(id.ToString() + idChildren.ToString()) + ","text":"" + dr[1] + ""}";
}
}
else
{
idChildren++;
dataJson = dataJson + ",{"id":" + Convert.ToInt32(id.ToString() + idChildren.ToString()) + ","text":"" + dr[1] + ""}";
}
}
dataJson = dataJson + "]}]";
}
return dataJson;
}
function BindRoleList(value) {
$(value).combotree({
data: <%=DataTableToJson()%>,
//url: '/DesktopModules/ARB_OrgSys/GetOrgList.ashx',
valueField: 'id',
textField: 'text',
multiple:true
});
}
$(document).ready(function () {
BindRoleList("#cc");
$("#cc").combobox({
onChange: function (n,o) {
document.getElementById("<%=tree.ClientID%>").value=$("#cc").combotree("getText");
}
});
});
<input id="cc" class="easyui-combotree" style=" 100%" />