0
我正在使用C#.Net,我想知道 如何使用javascript突出顯示選定的treeview節點。關於javascript的ASp.net treeview幫助
我正在使用C#.Net,我想知道 如何使用javascript突出顯示選定的treeview節點。關於javascript的ASp.net treeview幫助
當填充樹狀你只需要添加一個JavaScript方法給每個節點,然後JavaScript方法顯示節點文本到文本框:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection sqlconn = new SqlConnection("--Your sql connection--");
sqlconn.Open();
DataSet ds = new DataSet();
SqlDataAdapter cmd = new SqlDataAdapter("SELECT * FROM --The table with your info--",sqlconn);
cmd.Fill(ds, "region");
DataTable dt = ds.Tables[0];
PopulateNodes(dt, TreeView1.Nodes);
}
private void PopulateNodes(DataTable dt, TreeNodeCollection nodes)
{
string temp = "";
foreach (DataRow dr in dt.Rows)
{
TreeNode tn = new TreeNode();
tn.Text = dr["Location"].ToString();
tn.Value = dr["Location"].ToString();
if (temp != tn.Text)
{
temp = tn.Text;
//tn.SelectAction = TreeNodeSelectAction.Expand;
tn.NavigateUrl = "javascript:tree('" + dr["--Column--"].ToString() + "')";
nodes.Add(tn);
AddChildNodes(dt, tn.ChildNodes, dr["--Column--"].ToString());
}
}
}
private void AddChildNodes(DataTable dt, TreeNodeCollection node, string p)
{
foreach (DataRow dr in dt.Rows)
{
TreeNode tn = new TreeNode();
if ((string)dr["Location"] == p)
{
tn.Text = dr["SubLocation"].ToString();
tn.Value = dr["SubLocation"].ToString();
tn.NavigateUrl = "javascript:tree('" + dr["--Column--"].ToString() + "')";
node.Add(tn);
}
}
}
的Javascript:
function tree(text) {
document.getElementById('<%=TextBox1.ClientID %>').value = text.valueOf();
}
你可以張貼一些代碼? – Vithozor