By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,569 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

Database update, treeview is not updating. Any idea ?

P: n/a
Hello,

I have a treeview that i fill from a database, when i update nodename
in database the treeview dont update. Its works when iam not useing
enableviewstate="true" but then i loosing the current selection and
stuff in the tree.

I post my code here, any idea ?

<asp:TreeView ID="SubMenuTree" EnableViewState="false" node
ExpandDepth="2" OnSelectedNodeChanged="nodeSelect"
OnTreeNodePopulate="PopulateNode" runat="server"
ImageSet="XPFileExplorer" NodeIndent="15">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False"
HorizontalPadding="0px"
VerticalPadding="0px" />
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black"
HorizontalPadding="2px"
NodeSpacing="0px" VerticalPadding="2px" />
<Nodes>
<asp:TreeNode Text="Root" SelectAction="Select"
PopulateOnDemand="True" Value="0"/>
</Nodes>
</asp:TreeView>

public class SubMenu : Selago.Admin.UserControl.BaseUserControl
{

protected List<iPagePageList;
protected List<iPageChildrenList;
protected string Script;
protected string javascript;
protected TreeView SubMenuTree;
protected UpdatePanel MenuUpdatePanel;
public static event NavigateEventHandler navigate;

public delegate void NavigateEventHandler(object sender,
NavigateEventArgs e);

public class NavigateEventArgs : EventArgs
{
public int pageid = 0;
}

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}

protected void PopulateNode(Object sender, TreeNodeEventArgs
e)
{
// Call the appropriate method to populate a node at a
particular level.
switch (e.Node.Depth)
{
case 0:
// Populate the first-level nodes.
PopulateTopLevelNodes(e.Node);
break;
case 1:
// Populate the second-level nodes.
PopulateChildern(e.Node);
break;
default:
// Do nothing.
break;
}

}
private void PopulateTopLevelNodes(TreeNode node)
{

Selago.BusinessLayer.Service service = new
Selago.BusinessLayer.Service();
PageList = service.GetPages();

foreach(iPage page in PageList)
{
if(page.ParentID == 0)
{

TreeNode TopLevel = new TreeNode();

TopLevel.Text = page.PageName;
TopLevel.Value = page.ID.ToString();

// Add root node to TreeView
TopLevel.PopulateOnDemand = true;
TopLevel.SelectAction =
TreeNodeSelectAction.SelectExpand;
//TopLevel.NavigateUrl = "../../../Admin/
Default.aspx?id=" + page.ID;

if (CurrentPage.ID.Equals(page.ID))
{
TopLevel.Selected = true;
TopLevel.SelectAction =
TreeNodeSelectAction.SelectExpand;
}

node.ChildNodes.Add(TopLevel);

}
}
}

private void PopulateChildern(TreeNode node)
{

Selago.BusinessLayer.Service service = new
Selago.BusinessLayer.Service();
ChildrenList =
service.GetChildrenPages(Int32.Parse(node.Value));

foreach (iPage page in ChildrenList)
{
TreeNode newNode = new TreeNode();

newNode.Text = page.PageName;
newNode.Value = page.ID.ToString();
// newNode.NavigateUrl = "../../../Admin/Default.aspx?
id=" + page.ID;

// Set additional properties for the node.
newNode.SelectAction =
TreeNodeSelectAction.SelectExpand;

// Add the new node to the ChildNodes collection of
the parent node.
node.ChildNodes.Add(newNode);

DataSet ChildrensSub = new DataSet();
int ChildrensSubCount =
service.GetChildrenPages(Int32.Parse(newNode.Value )).Count;

if (CurrentPage.ID.Equals(page.ID))
{
newNode.Selected = true;
newNode.SelectAction =
TreeNodeSelectAction.SelectExpand;
}

if (ChildrensSubCount 0)
{
PopulateChildern(newNode);
}

}
}
protected void nodeSelect(object sender, EventArgs e)
{
NavigateEventArgs args = new NavigateEventArgs();
args.pageid =
Int32.Parse(SubMenuTree.SelectedNode.Value.ToStrin g());
navigate(this, args);

// javascript = "OnPageClick(" +
SubMenuTree.SelectedNode.Value + ");";
}



Dec 4 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.