Solved

Best way to display recordset data in gridview?

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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