By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Nested GridViews plus DetailsView

P: n/a
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.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
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

Apr 27 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.