我想绑定一个前段是js库(Extjs)的Treeview。
因为都是js、所以我想从后台检索数据然后输出到前台、显示,怎么才能实现输出数据呢?我把js库直接去手动写的固定的格式贴出来给大家参看。然后net里面绑定Net你里面Treeview的代码贴出来作为参考 、希望能帮我合并一块使用Extjs的Tree输出树形来绑定。
Extjs Tree Demo:
var Firstroot=new Ext.tree.TreeNode({
id:"Firstroot",
style:'overflow: hidden;',
//icon:'Ext/resources/images/default/tree/elbow-end-plus.gif',
text:"服务平台",
qtip:'服务平台',
animate:true,
expanded:true
});
var ClientTree1 = new Ext.tree.TreeNode({
id: 'Client',
//icon:'Ext/resources/images/default/menu/menu-parent.gif',
text: '导航1',
expanded: true //展开显示
});
var CrootA1=new Ext.tree.TreeNode({
id:'CrootA1',
//icon:'Ext/resources/images/default/menu/menu-parent.gif',
text:'导航1',
qtip:'导航1',
leaf:true,
listeners:{
'click':function(node, event) {
event.stopEvent();
var n = tabs.getComponent(node.id);
if (!n) { //判断是否已经打开该面板
tabs.add({
id:node.id,
title:node.text ,
iconCls:'tabs',
html:'<iframe scrolling="no" id="iframe'+node.id+'" name="iframe'+node.id+'" frameborder="0" width="100%" height="100%" src="../koimy1/Showvideo.aspx"></iframe>',
closable:true
}).show();
}else
{
//已经打开则,刷新当前页面.
window.frames["iframe"+node.id].location.reload();
}
tabs.setActiveTab(n);
}
}
});
//添加子节点到第三个根节点
ClientTree1.appendChild(CrootA1);
Firstroot.appendChild(ClientTree1);
Net绑定事例:
public partial class Treeview_Default : System.Web.UI.Page
{
private DataTable tblSetOrgInfo = new DataTable();
private string strTextBox3_Text = "";
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string connstr = "server=.;uid=sa;pwd=koimy1234;database=koimy_bs;";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string cmdstr="SELECt 内部编号, 类别, AbsIndex, ItemIndex, ItemLevel, ParentIndex, 类别号, 单位编号, 单位名称, 拼音编码, 单位地址, 单位电话号码, 开户银行, 帐号, 开户全称 FROM 组织机构编码表 ORDER BY AbsIndex";
SqlDataAdapter sqldata=new SqlDataAdapter(cmdstr,conn);
sqldata.Fill(tblSetOrgInfo);
DataTable tempDataTable = tblSetOrgInfo.Copy();
DataView viewSetOrgInfo = new DataView(tempDataTable);
viewSetOrgInfo.RowFilter = "ItemLevel=0";
if (viewSetOrgInfo.Count > 0)
{
foreach (DataRowView myRow in viewSetOrgInfo)
{
string strEnterpriseName = myRow["单位名称"].ToString().Trim();
this.TreeView1.Nodes.Add(new TreeNode(strEnterpriseName));
PoppulateTreeView(strEnterpriseName, TreeView1.Nodes[0], myRow);
}
}
}
}
private void PoppulateTreeView(string parentPart, TreeNode parentNode, DataRowView parentRow)
{
string strEnterpriseName = "";
DataTable tempDataTable = tblSetOrgInfo.Copy();
DataView viewSetOrgInfo = new DataView(tempDataTable);
viewSetOrgInfo.RowFilter = "ParentIndex='" + parentRow["AbsIndex"].ToString().Trim() + "'";
foreach (DataRowView myRow in viewSetOrgInfo)
{
strEnterpriseName = myRow["单位名称"].ToString().Trim();
TreeNode myNode = new TreeNode(strEnterpriseName);
parentNode.ChildNodes.Add(myNode);
PoppulateTreeView(strEnterpriseName, myNode, myRow);
}
}
}