treeview怎么样设置使点击父节点文字展开子节点,而不刷新?
我想点击父节点的文字时和点击父节的“+”一样展开子节点?这样做主要是不会刷新,我应该怎么设置呀?
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindTreeView(menuTreeView, false, "0 ");
//menuTreeView.ShowExpand= true;
}
else
{
if (menuTreeView.SelectedNode.Expanded.Value)
{
menuTreeView.SelectedNode.Expanded = false;
}
else
{
menuTreeView.SelectedNode.Expanded = true;
//menuTreeView.Nodes[0].Expanded=true;
}
}
}
public DataSet GetCategorys()
{
SqlConnection conn = DB.CreateConn();
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter( "select * from admin_menu ", conn);
DataSet ds = new DataSet();
sda.Fill(ds);
conn.Close();
return ds;
}
public void BindTreeView(TreeView treeView, bool isExpanded, string sSelectData)
{
DataTable dataTable = GetCategorys().Tables[0];
treeView.Nodes.Clear();
DataRow[] rowList = dataTable.Select( "fatherid= '0 ' ");
if (rowList.Length <= 0) return;
foreach (DataRow row in rowList)
{
TreeNode rootNode = new TreeNode();
rootNode.Text = "≡ " + row[ "MENUNAME "].ToString() + " ≡ ";
rootNode.Value = row[ "MENUID "].ToString();
rootNode.Expanded = true;
//rootNode.NavigateUrl = row[ "url "].ToString();
//rootNode.Target = "right ";
rootNode.Expanded = isExpanded;
if (rootNode.Value == sSelectData)
{
rootNode.Selected = true;
}
treeView.Nodes.Add(rootNode);
CreateChildNode(rootNode, dataTable, isExpanded, sSelectData);
}
}
private void CreateChildNode(TreeNode parentNode, DataTable dataTable, bool isExpanded, string sSelectedData)
{
DataRow[] rowList = dataTable.Select( "fatherid= ' " + parentNode.Value + " ' ", "menuid ");
foreach (DataRow row in rowList)
{
TreeNode node = new TreeNode();
node.Text = row[ "MENUNAME "].ToString();
node.Value = row[ "MENUID "].ToString();
//node.ImageUrl = "images/02.gif ";
node.NavigateUrl = row[ "url "].ToString();
node.Target = "right ";
node.Expanded = isExpanded;
if (node.Value == sSelectedData)
{
node.Selected = true;
}
parentNode.ChildNodes.Add(node);
CreateChildNode(node, dataTable, isExpanded, sSelectedData);
}
}
[解决办法]
node.SelectAction = TreeNodeSelectAction.Expand;
[解决办法]
node.SelectAction = TreeNodeSelectAction.Expand;
楼上的 正解