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

Dynamic sql and field results on detail table

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
M Carolina M Donda
Top achievements
Rank 1
M Carolina M Donda asked on 07 Jul 2008, 08:21 PM
I'm almost finished with my first hierachical table, but there still one problem to solve. Since I'm using a dynamic sql that result different type of result (not the same structure - different field names and data), when i open for the first time the result is fine, but the second one to open with the structure of the first query.

I guess I just need to reset somehow the detail table wich now is configured to AutoGeneratedColumns and I'm using the ItemCreated Event of RadGrid to change the columns names.

Some part of the code that bind the data to Detail table.

protected void rg_test_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e) 
    { 
        if (e.DetailTableView.Name.Equals("detail")) 
        { 
            System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand("[pr_rpt_user_detail]"
                new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["db_misa_conn_string"].ConnectionString)); 
            comm.CommandType = CommandType.StoredProcedure; 
 
            Hashtable values = new Hashtable(); 
            e.DetailTableView.ParentItem.ExtractValues(values); 
            comm.Parameters.AddWithValue("@id_user", Convert.ToInt32(Session["id_user"])); 
            comm.Parameters.AddWithValue("@id_user_rpt", Convert.ToInt32(values["id_user_rpt"])); 
            comm.Parameters.AddWithValue("@id_rate_control", Convert.ToInt32(values["id_rate_control"])); 
 
            System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(comm); 
            DataTable dt = new DataTable(); 
            da.Fill(dt); 
            e.DetailTableView.DataSource = dt; 
      } 
 


Thanks.

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 08 Jul 2008, 02:07 PM
Hello Carol,

Please note that the DetailTableDataBind event is used for binding your detail tables every time you are expanding an item with HierarchyLoadMode= ServerBind or ServerOnDemand(default). Therefore, the best approach is to set your custom SQL commands in that event and let RadGrid autogenerate its column. Another option is to use data source controls (as of ASP.NET 2.0) where you can define different SqlDataSource control for different stored procedures in the database and conditionally bind detail tables to them.

Regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
M Carolina M Donda
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or