asp.net 中treeview 点击节点触发事件的问题
我想做一个省份管理的页面想用treeview来做现在的问题是:根:福建省(点击此处获取TreeNode.value触发事件)+福州市(点击此处获取TreeNode.val...
我想做一个省份管理的页面
想用treeview来做
现在的问题是:
根:福建省 (点击此处获取TreeNode.value 触发事件)
+ 福州市 (点击此处获取TreeNode.value 触发事件)
- 鼓楼区 (点击此处获取TreeNode.value 触发事件)
- 某某区
也就是各节点 触发不同的事件 怎么实现???
源代码如下(目前只是将列表显示了出来..):
//省份
protected void GetProvince()
{
DataSet TempDB = Keng.Components.Area.ProvinceList();
if (TempDB != null)
{
foreach (DataRow dr in TempDB.Tables[0].Rows)
{
TreeNode TnRoot = new TreeNode();
TnRoot.Text = dr["ProvinceName"].ToString();
TnRoot.Value = dr["ID"].ToString();
TnRoot.Expanded = false;
TnRoot.SelectAction = TreeNodeSelectAction.Expand;
TreeArea.Nodes.Add(TnRoot);
GetCity(TnRoot, dr["ID"].ToString(), Keng.Components.Area.CityList());
}
}
}
protected void GetCity(TreeNode Node,string ProID,DataSet city)
{
DataRow[] rows = city.Tables [0].Select("ProvinceID =" + Node.Value + "");
string a = Node.Value;
foreach (DataRow row in rows)
{
TreeNode childnode = new TreeNode();
childnode.Text = row["CityName"].ToString();
childnode.Value = row["ID"].ToString();
childnode.Expanded = false;
childnode.SelectAction = TreeNodeSelectAction.Expand;
Node.ChildNodes.Add(childnode);
GetArea(childnode, row["ID"].ToString(), Keng.Components.Area.AreaList());
}
}
protected void GetArea(TreeNode Node, string ProID, DataSet area)
{
DataRow[] rows = area.Tables[0].Select("CityID =" + Node.Value + "");
string a = Node.Value;
foreach (DataRow row in rows)
{
TreeNode childnode2 = new TreeNode();
childnode2.Text = row["AreaName"].ToString();
childnode2.Value = row["ID"].ToString();
// childnode.NavigateUrl = "AddAdmin.aspx?id=" + childnode.Value;
childnode2.Expanded = false;
Node.ChildNodes.Add(childnode2);
}
} 展开
想用treeview来做
现在的问题是:
根:福建省 (点击此处获取TreeNode.value 触发事件)
+ 福州市 (点击此处获取TreeNode.value 触发事件)
- 鼓楼区 (点击此处获取TreeNode.value 触发事件)
- 某某区
也就是各节点 触发不同的事件 怎么实现???
源代码如下(目前只是将列表显示了出来..):
//省份
protected void GetProvince()
{
DataSet TempDB = Keng.Components.Area.ProvinceList();
if (TempDB != null)
{
foreach (DataRow dr in TempDB.Tables[0].Rows)
{
TreeNode TnRoot = new TreeNode();
TnRoot.Text = dr["ProvinceName"].ToString();
TnRoot.Value = dr["ID"].ToString();
TnRoot.Expanded = false;
TnRoot.SelectAction = TreeNodeSelectAction.Expand;
TreeArea.Nodes.Add(TnRoot);
GetCity(TnRoot, dr["ID"].ToString(), Keng.Components.Area.CityList());
}
}
}
protected void GetCity(TreeNode Node,string ProID,DataSet city)
{
DataRow[] rows = city.Tables [0].Select("ProvinceID =" + Node.Value + "");
string a = Node.Value;
foreach (DataRow row in rows)
{
TreeNode childnode = new TreeNode();
childnode.Text = row["CityName"].ToString();
childnode.Value = row["ID"].ToString();
childnode.Expanded = false;
childnode.SelectAction = TreeNodeSelectAction.Expand;
Node.ChildNodes.Add(childnode);
GetArea(childnode, row["ID"].ToString(), Keng.Components.Area.AreaList());
}
}
protected void GetArea(TreeNode Node, string ProID, DataSet area)
{
DataRow[] rows = area.Tables[0].Select("CityID =" + Node.Value + "");
string a = Node.Value;
foreach (DataRow row in rows)
{
TreeNode childnode2 = new TreeNode();
childnode2.Text = row["AreaName"].ToString();
childnode2.Value = row["ID"].ToString();
// childnode.NavigateUrl = "AddAdmin.aspx?id=" + childnode.Value;
childnode2.Expanded = false;
Node.ChildNodes.Add(childnode2);
}
} 展开
展开全部
<script runat="server">
void Select_Change(Object sender, EventArgs e)
{
Message.Text = "You selected: " + LinksTreeView.SelectedNode.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>TreeView SelectedNodeStyle Example</h3>
<asp:TreeView id="LinksTreeView"
Font-Name= "Arial"
ForeColor="Blue"
SelectedNodeStyle-ForeColor="Green"
SelectedNodeStyle-VerticalPadding="0"
OnSelectedNodeChanged="Select_Change"
runat="server">
<LevelStyles>
<asp:TreeNodeStyle ChildNodesPadding="10"
Font-Bold="true"
Font-Size="12pt"
ForeColor="DarkGreen"/>
<asp:TreeNodeStyle ChildNodesPadding="5"
Font-Bold="true"
Font-Size="10pt"/>
<asp:TreeNodeStyle ChildNodesPadding="5"
Font-UnderLine="true"
Font-Size="10pt"/>
<asp:TreeNodeStyle ChildNodesPadding="10"
Font-Size="8pt"/>
</LevelStyles>
<Nodes>
<asp:TreeNode Text="Table of Contents"
SelectAction="None">
<asp:TreeNode Text="Chapter One">
<asp:TreeNode Text="Section 1.0">
<asp:TreeNode Text="Topic 1.0.1"/>
<asp:TreeNode Text="Topic 1.0.2"/>
<asp:TreeNode Text="Topic 1.0.3"/>
</asp:TreeNode>
<asp:TreeNode Text="Section 1.1">
<asp:TreeNode Text="Topic 1.1.1"/>
<asp:TreeNode Text="Topic 1.1.2"/>
<asp:TreeNode Text="Topic 1.1.3"/>
<asp:TreeNode Text="Topic 1.1.4"/>
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Chapter Two">
<asp:TreeNode Text="Section 2.0">
<asp:TreeNode Text="Topic 2.0.1"/>
<asp:TreeNode Text="Topic 2.0.2"/>
</asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Appendix A" />
<asp:TreeNode Text="Appendix B" />
<asp:TreeNode Text="Appendix C" />
</Nodes>
</asp:TreeView>
<br><br>
<asp:Label id="Message" runat="server"/>
</form>
</body>
</html>
void Select_Change(Object sender, EventArgs e)
{
Message.Text = "You selected: " + LinksTreeView.SelectedNode.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>TreeView SelectedNodeStyle Example</h3>
<asp:TreeView id="LinksTreeView"
Font-Name= "Arial"
ForeColor="Blue"
SelectedNodeStyle-ForeColor="Green"
SelectedNodeStyle-VerticalPadding="0"
OnSelectedNodeChanged="Select_Change"
runat="server">
<LevelStyles>
<asp:TreeNodeStyle ChildNodesPadding="10"
Font-Bold="true"
Font-Size="12pt"
ForeColor="DarkGreen"/>
<asp:TreeNodeStyle ChildNodesPadding="5"
Font-Bold="true"
Font-Size="10pt"/>
<asp:TreeNodeStyle ChildNodesPadding="5"
Font-UnderLine="true"
Font-Size="10pt"/>
<asp:TreeNodeStyle ChildNodesPadding="10"
Font-Size="8pt"/>
</LevelStyles>
<Nodes>
<asp:TreeNode Text="Table of Contents"
SelectAction="None">
<asp:TreeNode Text="Chapter One">
<asp:TreeNode Text="Section 1.0">
<asp:TreeNode Text="Topic 1.0.1"/>
<asp:TreeNode Text="Topic 1.0.2"/>
<asp:TreeNode Text="Topic 1.0.3"/>
</asp:TreeNode>
<asp:TreeNode Text="Section 1.1">
<asp:TreeNode Text="Topic 1.1.1"/>
<asp:TreeNode Text="Topic 1.1.2"/>
<asp:TreeNode Text="Topic 1.1.3"/>
<asp:TreeNode Text="Topic 1.1.4"/>
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Chapter Two">
<asp:TreeNode Text="Section 2.0">
<asp:TreeNode Text="Topic 2.0.1"/>
<asp:TreeNode Text="Topic 2.0.2"/>
</asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="Appendix A" />
<asp:TreeNode Text="Appendix B" />
<asp:TreeNode Text="Appendix C" />
</Nodes>
</asp:TreeView>
<br><br>
<asp:Label id="Message" runat="server"/>
</form>
</body>
</html>
追问
根:福建省
+ 福州市
- 鼓楼区
点击“鼓楼区” 返回 鼓楼区 value的值 与 “福州市” value 的值 与 “福建省” value 的值
怎么做?
就是要得到各子节点的值
展开全部
给TreeView添加一个 SelectedNodeChanged事件
protected void treeView1_SelectedNodeChanged(object sender, EventArgs e)
{
//this.treeView1.SelectedNode.Value; //取treeView1选中节点的Value
}
protected void treeView1_SelectedNodeChanged(object sender, EventArgs e)
{
//this.treeView1.SelectedNode.Value; //取treeView1选中节点的Value
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
二楼的答案
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询