Solved

Best way to display recordset data in gridview?

Posted on 2006-11-28
2
853 Views
Last Modified: 2011-09-20
Hi

I am not new to web dev but new to .net and VS2005.  I'm using VB.

I have the following data (SQL 2000) that I want to display:

TABLE1
-ID
-Date

TABLE2
-Table1ID
-Heading

For each ID in table 1 there will be several 'Headings' in table 2.  I want each row in a gridview to display the date from table1 in one column and then in a second column I want to display all the headings in table 2 for the date displayed in column 1 (inner join on table1.ID = table2.table1ID).  Each date should only display once with a vertical list of headings beside it.

If I just get the data in one SELECT query then it displays each heading in a new row with the date repeated for each one.  Do I need to put a new gridview inside the second column (of the first gridview) to display each heading?  But if I do that then I'm hitting the database with 2 separate queries, which doesn't sound like 'best practise'.  

I'm interested to hear what you think is the best approach to this.

Thanks a lot,
Danik
0
Comment
Question by:Danik_S
2 Comments
 
LVL 9

Accepted Solution

by:
kraffay earned 125 total points
ID: 18032705
You're looking at having to nest gridviews, a fairly common practice.  You could get all your data and store it in local datasets that you filter on in memory at run time, if database load is an issue.  

The key is to bind your child gridviews on the OnDataBound event of your master GridView.
0
 

Author Comment

by:Danik_S
ID: 18109795
Hi again

I've got this working using the RowDataBound event to get the ID of the row from the parent gridview and pass it to the SELECT query of the child gridview.  The code looks like this:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim s As SqlDataSource = CType(e.Row.FindControl("SQLDataSource2"), SqlDataSource)
            s.SelectParameters(0).DefaultValue = e.Row.Cells(0).Text
        End If
End Sub

But, this only works if the ID column of the parent gridview is visible.  I don't want the ID to be visible since it's meaningless to the user.  So how can I pass the ID for the row to the child gridview's select statement without displaying it in the parent gridview?

Many thanks.
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

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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: …

948 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

24 Experts available now in Live!

Get 1:1 Help Now