Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-17
6
Medium Priority
?
618 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

 
LVL 8

Accepted Solution

by:
gregasm earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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