Nested GridViews plus DetailsView

Discussion in 'ASP .Net' started by manuel.ricca@gmail.com, Apr 27, 2006.

  1. Guest

    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
     
    , Apr 27, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. The LoxFather

    C plus plus vs C Sharp

    The LoxFather, Aug 9, 2003, in forum: C++
    Replies:
    23
    Views:
    9,318
  2. Roy
    Replies:
    1
    Views:
    3,843
  3. The LoxFather

    C plus plus vs C Sharp

    The LoxFather, Aug 9, 2003, in forum: C Programming
    Replies:
    23
    Views:
    1,429
  4. Rahul
    Replies:
    9
    Views:
    440
    Andrey Tarasevich
    Mar 25, 2008
  5. furqan shaikh

    c plus plus code comparator

    furqan shaikh, Nov 7, 2008, in forum: C++
    Replies:
    6
    Views:
    838
    red floyd
    Nov 12, 2008
Loading...

Share This Page