Load RadListView depending on what link was clicked in TreeView

6 posts, 1 answers
  1. visionXpert
    visionXpert avatar
    9 posts
    Member since:
    Jun 2012

    Posted 21 Jun 2012 Link to this post

    I'm having a bad brain fart day... so i need a bit of help.

    I have a RadTreeView looks like this

    Root                                            RadListView Goes Here
    --Group1
       +-- 1a     
       +-- 1b
       +-- 1c
    --Group2
       +-- 2a    
       +-- 2b
       +-- 2c


    beside the above treeview, i have a RadListView in which i want to display a list of users based on what is passed by clicking anything in the treeview (ie: 1a, 1b, 1c, 2a, 2b, 2c)

    I want to bind RadListView on  RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e) event

    whats the best way of doing this?
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Jun 2012 Link to this post

    Hi,

    Here is the sample code which I tried based on your scenario.

    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" runat="server"  onnodeclick="RadTreeView1_NodeClick"  >
                <Nodes>
                    <telerik:RadTreeNode Text="Node1" Value="Name1" >
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="Node2" Value="Name2" >
                    </telerik:RadTreeNode>
                </Nodes>
    </telerik:RadTreeView>
    <telerik:RadListView ID="RadListView1" runat="server" >
                <ItemTemplate>
                   <span>
                    <label> <%#Eval("FirstName") %> </label> <label> <%#Eval("LastName")%> </label>                                     
                    </span>                                     
                </ItemTemplate>
    </telerik:RadListView>

    C#:
    protected void RadTreeView1_NodeClick(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
        {
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT FirstName,LastName FROM Employees WHERE FirstName='"+ e.Node.Value +"' ", con);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            RadListView1.DataSource = dt;
        }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. visionXpert
    visionXpert avatar
    9 posts
    Member since:
    Jun 2012

    Posted 22 Jun 2012 Link to this post

    one thing, instead of having the ListView be databound, can you provide me with an example of how to add items to the list in a loop?

    I'm hoping to do something like

     while (rdr.Read())
     {
            ListView Add item ("<a href=\""+some url+"?SomethingToPass="+rdr["SomeValue"]+"\"">"+rdr["userName"]+"</a>");
     }

    As you can see i want my ListItem to be a link (not a simple label)

    Please help as i'm somehow not my normal resourceful self

    Thanks
  5. visionXpert
    visionXpert avatar
    9 posts
    Member since:
    Jun 2012

    Posted 25 Jun 2012 Link to this post

    tried this approach and there still isn't a refresh of the ListView on TreeNodeClick....

    Debugger stops and shows there is actually values being placed in the label control, but it does not show the values after it runs through all the code, any ideas?

    thanks
  6. visionXpert
    visionXpert avatar
    9 posts
    Member since:
    Jun 2012

    Posted 26 Jun 2012 Link to this post

    This just isn't working...

    Here is what i have

    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="ScriptManager1" runat="server"
            EnableTheming="True">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI"
                    Name="Telerik.Web.UI.Common.Core.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI"
                    Name="Telerik.Web.UI.Common.jQuery.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI"
                    Name="Telerik.Web.UI.Common.jQueryInclude.js">
                </asp:ScriptReference>
            </Scripts>
        </telerik:RadScriptManager>
     
        
           <table width="100%" border="2">
           <tr><td>
                <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" width="226px">
                <telerik:RadTreeView ID="RadTreeView1" Runat="server" 
                    Width="209px" Skin="Outlook" onnodeclick="RadTreeView1_NodeClick"  >
                     
                </telerik:RadTreeView>
                </telerik:RadAjaxPanel>
               </td><td>
                
             
                   <br />
                   <br />
                <telerik:RadListView ID="RadListView1" runat="server" >
                    <ItemTemplate>
                       <span>
                        <label> <%#Eval("ReportParmName") %> </label> <label> <%#Eval("ReportParmValue")%> </label>                                    
                        </span>                                    
                    </ItemTemplate>
                </telerik:RadListView>          
             
            </td></tr>
            </table>
          
        </form>
    </body>

    and codebehind

    protected void Page_Load(object sender, EventArgs e)
       {
     
      
           if (!Page.IsPostBack)
           {
               SqlDataAdapter adapter = new SqlDataAdapter("SELECT * From Reports", ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString);
               DataSet links = new DataSet();
               adapter.Fill(links);
               RadTreeView1.DataTextField = "Description";
               RadTreeView1.DataFieldID = "id";
               RadTreeView1.DataFieldParentID = "ParentID";
               RadTreeView1.DataValueField = "id";
               RadTreeView1.DataSource = links;
               RadTreeView1.DataBind();
                
               RadTreeView1.ExpandAllNodes();
           }
       }
     
       protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
       {
     
           
           SqlDataAdapter adapter = new SqlDataAdapter("SELECT * From ReportParameters where ReportID=" + e.Node.Value + "", ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString);
           DataSet links = new DataSet();
           adapter.Fill(links);
           RadListView1.DataSource = links.Tables[0];
       }


    and while my RadTreeView1_NodeClick() fires and it seems to be filling the table with result from the query, nothing is showing..

    Please HELP!
  7. visionXpert
    visionXpert avatar
    9 posts
    Member since:
    Jun 2012

    Posted 26 Jun 2012 Link to this post

    so after banging my head on the wall....

    it looks like my RadListView was outside of my RadAjaxPanel...

    placing the RadAjaxPanel below the closing tag of my RadListView made this all work.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017