Solved

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

Posted on 2004-08-17
6
600 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

8 Experts available now in Live!

Get 1:1 Help Now