Nested GridViews plus DetailsView

M

manuel.ricca

Hello,

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:


A1
A A2
A3

B1
B B2
B3

C1
C C2
C3

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 =
(GridView)e.Row.FindControl("GridView2");

SqlDataSource sds = new
SqlDataSource(System.Configuration.ConfigurationManager.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
art.ar_stat03,FA_Intitule");
gv.DataSource = sds;
gv.AutoGenerateColumns = false;

HyperLinkField hf = new HyperLinkField();
hf.DataTextField = "FA_Intitule";
gv.Columns.Add(hf);

gv.RowDataBound += new
GridViewRowEventHandler(gv_RowDataBound);

gv.DataBind();
}
}

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,955
Messages
2,570,125
Members
46,706
Latest member
liammiller

Latest Threads

Top