Solved

Best way to display recordset data in gridview?

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 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