Gridview. Fill dataset with various tables

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have 2 SQL tables as follows:

[Articles] > ArticleId (PK), Title, Body
[Categories] > CategoryId (PK), ArticleId (FK), CategoryName

Basically I want to display a GridView with the articles.
Then for each article I want to have child gridview with the comments.

I suppose I need to have a dataset with 2 tables, one for Articles and
other for comments.

How can I create this in ASP.NET 2.0?
And how should my SQL 2005 Stored Procedure return the data?

Thank You,
Miguel
 
On the command event for the "Articles" GridView, you can trap the selected
row of the parent grid. You can then get the PK and query the server for
the specific comments for that article and bind the table to the child
grivew

As far as the Stored Procedure is concerned, Table adapters make life so
much easier, tbh, its much easier to use them that to fart around with
stored procs unless performance is a grinding issue or procedures demand it.

In order to do that simple drag the required table to a dataset and then you
can add queries with parameters into the table adapter, this then can be
called from the table adaptes namespace for that dataset for example.

Dim ArticlesTableAdapter as new
MyDataSetTablerAdapters.ArticlesTableAdapter
Dim ArticleComments as MyDataSet.ArticleCommentsTable
ArticleComments = ArticlesTableAdapter.getCommentsByArticleID( ArticleID )

ChildGrid.DataSource=ArticleComments
ChildGrid.DataBind
 
Back
Top