This is a migrated thread and some comments may be shown as answers.

When User Clicked RadTreeview Node Radgrid has to populate

3 Answers 84 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
noyan
Top achievements
Rank 1
noyan asked on 06 Apr 2009, 08:47 AM

I got a gridview which I created with following code when user clicked one of treview node I have to populate a radgrid for given departmen. I dont know how can I catch treeview click event and without making any postback populate radgrid for clicked departmen. All help will be apreciated, thank you in advance.

    //Load Root Nodes...  
    private void LoadRootNodes()  
    {  
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Personelcon"].ConnectionString);  
        SqlCommand selectCommand = new SqlCommand("SELECT * FROM Department WHERE Reportsto IS NULL", connection);  
        SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);  
        DataTable data = new DataTable();  
        adapter.Fill(data);  
 
        foreach (DataRow row in data.Rows)  
        {  
            RadTreeNode node = new RadTreeNode();  
            node.ImageUrl = "themes/default/entity.gif";  
            node.Text = row["Dname"].ToString();  
            node.Value = row["Departmenid"].ToString();  
            node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;  
            RadTreeView1.Nodes.Add(node);  
        }  
    } 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 06 Apr 2009, 09:21 AM
Hello Noyan,

Try out the following code snippet.

ASPX:
 
<telerik:radtreeview id="RadTreeView1" runat="server" OnNodeClick="RadTreeView1_NodeClick">   
</telerik:radtreeview>   
   
<telerik:RadGrid ID="RadGrid1" runat="server">   
</telerik:RadGrid>  
  
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
    <AjaxSettings>  
        <telerik:AjaxSetting AjaxControlID="RadTreeView1">  
            <UpdatedControls>  
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />  
            </UpdatedControls>  
        </telerik:AjaxSetting>  
    </AjaxSettings>  
</telerik:RadAjaxManager> 

CS:
 
protected void LoadRootNodes()  
{  
    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Personelcon"].ConnectionString);  
    SqlCommand selectCommand = new SqlCommand("SELECT * FROM Department WHERE Reportsto IS NULL", connection);  
    SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);  
    DataTable data = new DataTable();  
    adapter.Fill(data);  
    foreach (DataRow row in data.Rows)  
    {  
        RadTreeNode node = new RadTreeNode();  
        node.ImageUrl = "themes/default/entity.gif";    
        node.Text = row["Dname"].ToString();  
        node.Value = row["Departmenid"].ToString();    
        node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;  
        RadTreeView1.Nodes.Add(node);  
    }    
}  
 
protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)  
{  
    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Personelcon"].ConnectionString);  
    SqlCommand selectCommand = new SqlCommand("SELECT * FROM Department WHERE Departmenid='" + e.Node.Value + "'", connection);  
    SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);  
    DataTable data = new DataTable();  
    adapter.Fill(data);  
    RadGrid1.DataSource = data;  
    RadGrid1.Rebind(); 

Adding AJAX Manager will avoid unnecessary page flickering.

Thanks,
Shinu.
0
Lakshmi
Top achievements
Rank 1
answered on 17 Aug 2015, 12:37 PM

Hi Shinu,

Thank you for your solution.

I was using the same code but i could not populate the grid onNodeClick event.

during debug i did not get any errors the grid is getting binded but i could not see the grid on the page.

If any one face the same issue please help me if you are aware of the solution.

Thank you,

Lakshmi

0
Peter Filipov
Telerik team
answered on 20 Aug 2015, 08:39 AM
Hello Lakshmi,

Please open a new support ticket for the RadGrid control and attach your solution. We will need to investigate the problem in order to give you direction what might be causing this behavior. Make sure that the AjaxManger is updating the grid control when the TreeView is doing a postback. For the purpose of the test you could remove the AjaxManager to be sure that everything is working as expected. 

Regards,
Peter Filipov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TreeView
Asked by
noyan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Lakshmi
Top achievements
Rank 1
Peter Filipov
Telerik team
Share this question
or