Solved

Best way to display recordset data in gridview?

Posted on 2006-11-28
2
854 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Have sliders change in order 2 22
C#  Radio button search for Date not DateTime 4 46
imap read mail 1 27
asp.net mvc5 6 14
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

785 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