Solved

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

Posted on 2004-08-17
6
605 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Latency in .net app using DB in .net 21 34
Linq Help 1 35
Change Format on Data when exporting to Excel 4 23
Get Client IP on RDS - VB.NET 15 29
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

16 Experts available now in Live!

Get 1:1 Help Now