I want to create a grid (e.g. with customerid, name and adress) and place inside one of its GridTemplateColumns another Grid, that shows data dependent on the customers ID (e.g. orders).
I know i can achieve this very easily with the MasterTableView/DetailTables
but i dont like the way the data is presented there (i need everything displayed horizontally).
Does anybody know, how this can be achieved?
I know i can achieve this very easily with the MasterTableView/DetailTables
but i dont like the way the data is presented there (i need everything displayed horizontally).
Does anybody know, how this can be achieved?
5 Answers, 1 is accepted
0
Hi,
I have created small example to illustrate you how to achieve this. Please check the attachment and let me know how it goes.
Sincerely yours,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I have created small example to illustrate you how to achieve this. Please check the attachment and let me know how it goes.
Sincerely yours,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
K.
Top achievements
Rank 1
answered on 16 Oct 2008, 03:56 PM
Hello Vlad,
thank you for your fast response!
First of all, your example works well, but it is not exactly what i needed (probably because i didn't explain it well enough :D )
The MasterTableView/DetailTables is allready very close to my needs, but i need the DetailTable in the same row as the MasterTable,.
Thanks in advance for your answer,
K.
thank you for your fast response!
First of all, your example works well, but it is not exactly what i needed (probably because i didn't explain it well enough :D )
The MasterTableView/DetailTables is allready very close to my needs, but i need the DetailTable in the same row as the MasterTable,.
Thanks in advance for your answer,
K.
0
Princy
Top achievements
Rank 2
answered on 17 Oct 2008, 03:52 AM
Hello,
You can get this done by using the DataKeyValue for the item in the main grid and then in the NeedDataSource event of the related grid, pass the datakeyvalue to the databinding select query for the related grid. Also set the DataKeyName of the main grid as the primary key datafield value. Try out the following code.
aspx:
cs:
Thanks
Princy.
You can get this done by using the DataKeyValue for the item in the main grid and then in the NeedDataSource event of the related grid, pass the datakeyvalue to the databinding select query for the related grid. Also set the DataKeyName of the main grid as the primary key datafield value. Try out the following code.
aspx:
| <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" runat="server"> |
| <MasterTableView DataKeyNames="ContID" DataSourceID="SqlDataSource1"> |
| <Columns> |
| <telerik:GridBoundColumn DataField="Countries" UniqueName="Countries"></telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="ContID" UniqueName="ContID"></telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn UniqueName="TemplateColumn"> |
| <ItemTemplate> |
| <telerik:RadGrid ID="RadGrid2" ShowHeader="false" AutoGenerateColumns="False" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource"> |
| <MasterTableView> |
| <Columns> |
| <telerik:GridBoundColumn DataField="Continents" UniqueName="Continents"></telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| .... |
cs:
| protected void RadGrid2_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
| { |
| RadGrid grid = (RadGrid)source; |
| GridDataItem item = (GridDataItem)grid.NamingContainer; |
| string strtxt = item.GetDataKeyValue("ContID").ToString(); |
| string ConnectionString = "Data Source=INC135; Initial Catalog=MyDataBase;User ID=sa; Password=softinc"; |
| SqlConnection conn = new SqlConnection(ConnectionString); |
| SqlCommand cmd = new SqlCommand(); |
| conn.Open(); |
| SqlDataAdapter adp = new SqlDataAdapter("select Continents FROM Continents where ContID=' " + strtxt + "'", conn); |
| DataTable dt = new DataTable(); |
| adp.Fill(dt); |
| grid.DataSource = dt; |
| conn.Close(); |
| } |
Thanks
Princy.
0
K.
Top achievements
Rank 1
answered on 17 Oct 2008, 12:21 PM
Creating described scenario warks fine now.
Thank you for your support!
Thank you for your support!
0
LiZ0r
Top achievements
Rank 1
answered on 13 May 2009, 05:04 AM
Great example!
But I have a question, with the example...
Can you add an export function to it (to either Excel or PDF)?
I am gettin an error when I try to export....the data bound to the Radgrid is being resetted to 0...
example a date is placed and when I export it changes the the date to 00/00/0000
But I have a question, with the example...
Can you add an export function to it (to either Excel or PDF)?
I am gettin an error when I try to export....the data bound to the Radgrid is being resetted to 0...
example a date is placed and when I export it changes the the date to 00/00/0000
