Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Nested GridViews plus DetailsView

Thread Tools

Nested GridViews plus DetailsView
Posts: n/a

I'm trying to create a table with 2 nested gridviews and then a
DetailsView on the right. The DetailsView should show the details of
the item selected in the 2nd (nested) GridView:

My "master" table is like this:

A A2

B B2

C C2

When I click on, for example, B2, the detailsview should be updated.
I created the second GridView inside a TemplateField of the first
GridView. Then I added a RowDataBound event handler to set the correct
data source to it:

protected void GridView1_rowDataBound(object sender,
GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
GridView gv =

SqlDataSource sds = new
SqlDataSource(System.Configuration.ConfigurationMa nager.ConnectionStrings["NBIIIS_05ConnectionString"].ToString(),
"SELECT distinct FA_Intitule, fam.FA_CodeFamille,
art.AR_Stat03 FROM F_FAMILLE fam INNER JOIN F_Article art ON
fam.FA_CodeFamille=art.FA_CodeFamille WHERE AR_Stat03='" +
((DataRowView)e.Row.DataItem)["AR_Stat03"].ToString() + "' ORDER BY
gv.DataSource = sds;
gv.AutoGenerateColumns = false;

HyperLinkField hf = new HyperLinkField();
hf.DataTextField = "FA_Intitule";

gv.RowDataBound += new


So far so good. However, what should I add as the field for the column
of the 2nd GridView to allow me to update the DetailsView? I tried
ButtonFields() but, because I'm creating the nested GridViews at
runtime, I couldn't figure out how to get the selected item after the
postback. Adding an event handler for RowCommand or SelectedItemChanged
doesn't work, even with EnableViewState as true.

Now, as can be seen, I'm trying HyperLinkFields but I can't set the
NavigateUrl properly, even at the RowDataBound handler of the nested
GridView. This is because I don't know how to access the HyperLinkField
of the row.
Anyway, I don't think this is the best way to do it.

Anyone can help?

Thanks in advance,

Manuel Ricca

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple nested gridviews JohnE ASP .Net 0 03-23-2010 07:45 AM
Gridviews and Nested Gridview katmagic ASP .Net 0 01-17-2009 11:56 PM
Nested GridViews In UserControls. Mr Nobody ASP .Net 2 07-25-2008 04:38 PM
Nested Gridviews Chris ASP .Net 1 04-01-2007 08:53 AM
"codeless" nested gridviews...there has to be a better way Roy ASP .Net 1 06-16-2006 05:35 PM