Link to home
Start Free TrialLog in
Avatar of dpmoney
dpmoneyFlag for United States of America

asked on

ASP.NET - Bind Gridview Datasource to a specific table in dataset

I have a functioning test ASPX page that calls a SINGLE SQL stored procedure.
That stored procedure returns 5 recordsets.
In the page load event, I'm able to fill a dataset with 5 distinct tables - one for each of the recordsets returned by the single SQL SP.
I know it is working because my response.write test code display the first column's field value from each table.
Now, I just need to figure out how to display this data as 5 distinct tables in the ASPX.
I was thinking 5 distinct gridviews since I can stylize them to my liking, sort etc.

However, how do I bind a gridview datasource to a specific table in a dataset?

Here is some of the page load code which works fine:

        'Troubleshooting - Verify data is filled
      Response.Write("Recordset #1: " & ds.Tables(0).Rows(0)("Location").ToString & "<br />")
        Response.Write("RecordSet #2: " & ds.Tables(1).Rows(0)("Username").ToString & "<br />")
      Response.Write("RecordSet #3: " & ds.Tables(2).Rows(0)("Shape").ToString & "<br />")
      Response.Write("RecordSet #4: " & ds.Tables(3).Rows(0)("Country").ToString & "<br />")
      Response.Write("RecordSet #5: " & ds.Tables(4).Rows(0)("MfgDate").ToString & "<br /><br />")

What I need is GridView1 bound to ds.Tables(0), GridView2 bound to ds.Tables(1), etc.

This does not work in the pageload:

   GridView1.DataSource = ds.Tables(0)
   GridView1.DataBind()

It fails with:  'GridView1' is not declared. It may be inaccessible due to its protection level.
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dpmoney

ASKER

I will test when I'm back in the office on Monday - thank you.
Avatar of dpmoney

ASKER

Thanks!  Your example code pointed me in the right direction!