Solved

Dataset/datatables as a source for a Datalist/Datagrid combination

Posted on 2004-08-17
6
608 Views
Last Modified: 2008-02-01
I have a report with a datagrid in the ItemTemplateColumn of a datalist.
The datalist is populated with one stored procedure call to the database
and the datagrid with a second stored procedure call on every datalist
ItemDataBound event.

I want to change this.

I want to make one stored procedure call and populate one dataset
with two datatables containing the info I need and create a
datarelation to link the two.

I can see how to get it going to the point where the datalist item
is being populated, but at that moment I don't know how to get to the
dataset and get the data I need for the datagrid.

Is this feasible and if so can you help me where I'm stuck?

Thanks!

0
Comment
Question by:JeffDrummond
  • 3
  • 3
6 Comments
 
LVL 8

Expert Comment

by:gregasm
ID: 11823471
You can modify the stored procedure to fill two datatables in the dataset by delimiting the queries with ';' like so:

SELECT * FROM Table1;SELECT * FROM Table2;SELECT * FROM Table3

When loaded into a dataset, you will get 3 tables in your dataset with the results from the 3 queries.

You can then bind the individual tables to the controls by references the tables by ordinal number:

myControl.datasource = myDs.tables(0);
myOtherControl.datasource = myDs.tables(1);

HTH,
Greg
0
 

Author Comment

by:JeffDrummond
ID: 11829734
Yes, I have the dataset populated with two tables
and a datarelation conecting the two.

The datalist is bound to Table 1.

When a datalist row is populated, I need to
populate the datagrid with the child rows in Table 2.

This is where I'm stuck.  How to get to the datasource
for the datagrid.
0
 
LVL 8

Expert Comment

by:gregasm
ID: 11832029
To implement the master - details datagrid, you must bind the details grid to the relationship object.

Have a look at this msdn walkthrough:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingmasterdetailslistwithdatagrid.asp
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 8

Accepted Solution

by:
gregasm earned 500 total points
ID: 11832100
The same principles of data binding apply for all types of .NET projects, whether they are windows or web based. The above link is to illustrate master-details in a win form. Here are also some ASP.NET databinding resources that may be helpful to you as well.

Heirarchical data binding with DataGrid and DataList:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspn-hierdatabinding.asp

Classic Master-Details ASP.NET implementation:
http://www.c-sharpcorner.com/asp/Articles/MasterDetailDCHK.asp

Heirarchical dataGrid Tutorial <-- a favorite of mine =]
http://www.dotnetjunkies.com/Tutorial/841522C9-FFBD-4C57-BD48-F62B55057FF3.dcik
0
 

Author Comment

by:JeffDrummond
ID: 12068929
I have the datarelation set up.  When I run the report now I am getting
an error:  "A field or property with the name 'CaseDescript' was not found on the selected datasource."
The datasource is my datatable dtCaseTypes and the 'CaseDescript' column IS present in the
datasource.

This is my code-behind:

            dtActivJPO = New DataTable
            dtCaseTypes = New DataTable
            '--set datatable to first table in dataset
            dtActivJPO = ds.Tables(0)
            '--set datatable to second table in dataset
            dtCaseTypes = ds.Tables(1)
            '--create relationship between the two datatables
            drl = New DataRelation("JPOCaseTypes", _
                    ds.Tables(0).Columns("EmployeeID"), _
                    ds.Tables(1).Columns("EmployeeID"), False)
            '--add the relationship to the dataset
            ds.Relations.Add(drl)

            dvActivJPO = New DataView(dtActivJPO)

            dlActivJPO.DataSource = dvActivJPO
            dlActivJPO.DataBind()

This is the datagrid which displays the child rows:

                                                                        <asp:datagrid id=dgJPOCaseTypes runat="server" Width="770px" ShowFooter="True" CellPadding="2" GridLines="None" BorderWidth="0px" DataSource='<%# Container.DataItem.Row.GetChildRows("JPOCaseTypes") %>' autogeneratecolumns="False">

<Columns>
<asp:BoundColumn DataField="CaseDescript" SortExpression="CaseDescript" HeaderText="Caseload Types Assigned">
<HeaderStyle HorizontalAlign="Left" CssClass="ProductHeader"></HeaderStyle>
<ItemStyle HorizontalAlign="Left" CssClass="ItemStyle" VerticalAlign="Top"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:datagrid></TD>
0
 

Author Comment

by:JeffDrummond
ID: 12142052
I've got this up and running.  The columns not being found
in my previous post were BoundColumns, and I needed to
change them to template columns in order for the
GetChildRows to work.  

So using the datarelation and the GetChildRows
method works perfectly.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Not showing JavaScript in the list 5 52
Reading the Web.Config using IIS 7.5? 4 35
Crystal reports vb.net 2 39
.NET 2008 VB and C# 6 27
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now