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

Hierarchical Grid-Add GridTableView programatically doubt

1 Answer 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
cristian
Top achievements
Rank 1
cristian asked on 27 Jul 2011, 07:05 PM

I created a RadGrid programmatically, and i use the following lines:

 

 

     RadGrid2.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid2_NeedDataSource);

 

instead of  --->   

RadGrid2.DataSourceID = "SqlDataSource1";

 

 

 

i want to create a GridTableView like the above line

 


GridTableView
tableViewOrders = new GridTableView(RadGrid2);

 

¿¿ what should be the declaration to replace ----> tableViewOrders.DataSourceID = "SqlDataSource2"; ???

 

i think somesthing like --->

 

tableViewOrders.NestedViewSettings.DataSourceID += new GridNestedViewSettings(RadGrid3_NeedDataSource);

 

 

but it is incorrect.



tableViewOrders.DataKeyNames =

new string[] { "idCodigos" };

 

 

GridRelationFields relationFields = new GridRelationFields();

 

relationFields.MasterKeyField =

"idCodigo";

 

relationFields.DetailKeyField =

"idCodigoSubGrupo";

 

tableViewOrders.ParentTableRelation.Add(relationFields);

RadGrid2.MasterTableView.DetailTables.Add(tableViewOrders);

 


protected

 

void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

 

{

 

 

ConnectionStringSettings connectionString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"];

 

_connection =

DbProviderFactories.GetFactory(connectionString.ProviderName).CreateConnection();

 

_connection.ConnectionString = connectionString.ConnectionString;

 

IDataReader reader;

 

 

using (IDbCommand command = _connection.CreateCommand())

 

{

command.CommandText =

"SpName";

 

command.CommandType =

CommandType.StoredProcedure;

 

_connection.Open();

reader = command.ExecuteReader();

}

((

RadGrid)source).DataSource = reader;

 

}

 

protected void RadGrid2_DataBound(object sender, EventArgs e)

 

{

 

if (_connection.State == ConnectionState.Open)

 

{

_connection.Close();

}

}


thanks in advance

Cristian.-

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 02 Aug 2011, 12:28 PM
Hi Cristian,

When programmatically binding a RadGrid you need to simply attach the NeedDataSource and DetailTableDataBind events. Then, you can see an example of how they are handled in this help article:
Hierarchical data-binding using DetailTableDataBind event

Kind regards,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
cristian
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or