Solved

Best way to display recordset data in gridview?

Posted on 2006-11-28
2
852 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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
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…

743 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

18 Experts available now in Live!

Get 1:1 Help Now