Treeview onselectednodechanged doesnt fires up

Discussion in 'Software' started by jcast, Jun 20, 2012.

  1. jcast

    jcast Private E-2

    Hi;

    I have a treeview comming from database, now I need to click on each category to see the contents (I am doing a FAQ page); well when I add onselectednodechanged property to the treeview I get a compilation error. looks like it does not want to fire up; here is the code:

    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    </asp:Content>

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:UpdatePanel runat="server" ID="upFAQ" UpdateMode="Conditional">
    <ContentTemplate>
    <div>
    <table class="formTbl width100">
    <tr>
    <th class="formHeader" colspan="2">Frequently Asked Questions</th>
    </tr>
    <tr>
    <td>
    <asp:TreeView ID="treeViewCategories" SelectedNodeStyle-ForeColor="Green"
    SelectedNodeStyle-VerticalPadding="0" runat="server"
    onselectednodechanged="Select_Change">
    </asp:TreeView>
    </td>
    <td><asp:Label runat="server" ID="Message1"></asp:Label></td>
    </tr>
    </table>
    </div>
    </ContentTemplate>
    </asp:UpdatePanel>
    </asp:Content>

    =========== Code Behind ========

    public partial class FAQ : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    PopulateTreeView(0, null);
    }
    }

    private void PopulateTreeView(int categoryParentId, TreeNode parentNode)
    {
    var categorySvc = new Shared.Core.CategorySvc();
    List<CategoryInfo> allCategories = categorySvc.GetAllCategories();

    var filteredItems = allCategories.Where(x => x.CategoryParentId == categoryParentId);

    foreach (var cat in filteredItems)
    {
    TreeNode childNode = new TreeNode();
    childNode = new TreeNode(cat.CategoryName);

    if (parentNode == null)
    {
    treeViewCategories.Nodes.Add(childNode);
    }
    else
    {
    parentNode.ChildNodes.Add(childNode);
    }
    PopulateTreeView(cat.CategoryId, childNode);
    }
    }

    private void Select_Change(Object sender, EventArgs e)
    {
    Message1.Text = "You selected: " + treeViewCategories.SelectedNode.Text;
    }
    }

    if I delete the onselectednodechanged="Select_Change" from the tree view I get my tree fine; but if I add the property back onselectednodechanged="Select_Change" then I got an error:

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1061: 'ASP.support_faq_aspx' does not contain a definition for 'Select_Change' and no extension method 'Select_Change' accepting a first argument of type 'ASP.support_faq_aspx' could be found (are you missing a using directive or an assembly reference?)

    Source Error:


    Line 23: <tr>
    Line 24: <td>
    Line 25: <asp:TreeView ID="treeViewCategories" SelectedNodeStyle-ForeColor="Green"
    Line 26: SelectedNodeStyle-VerticalPadding="0" runat="server"
    Line 27: onselectednodechanged="Select_Change">

    I need to be able to click on each node and bring the information from the database but I dont know why the onselectnodechanged doesnt work. Can anyone help me please??

    Thanks

    Alexandra
     
  2. jcast

    jcast Private E-2

    I already found the answer. We can mark this as Resolved.

    Thanks
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds