Search code examples
devexpressmaster-detailaspxgridview

Button in DetailRow needs the keys from the two upper nested APSxGridViews


I do have two nested APSxGridView objects. The DetailRow in the inner one contains also a button. I want to initialize the button so that it launches new window in the browser. For that, I need the key id's from the upper GridViews.

GridView1
    GridView2
         DetailRow
             Button

I already know how to get the key from the GridView2 -- my existing code looks like:

protected void btnModify_Init(object sender, EventArgs e)
{
        ASPxButton btn = sender as ASPxButton;
        GridViewDetailRowTemplateContainer clsdetail = btn.Parent as GridViewDetailRowTemplateContainer;

        string partition = "1"; // this should be filled with the GridView1 id
        string cls = clsdetail.KeyValue.ToString(); // this is the GridView2 id

        // The following code just uses the information.
        string panelid = "t" + partition + "-" + cls;

        btn.ClientSideEvents.Click =
            String.Format("function(s, e){{ window.open('producttag.aspx?partition={0}&cls={1}','{2}'); }}",
                partition, cls, panelid);
}

Notice the string cls = ... that gets the key from the inner grid (the button is inside its detail row).

How can I get the key for the outer gridview? Can I do it through parents again? Or is there any other way?

Update: More than one detail row can be expanded in the inner grid view. This way, I cannot pass the id's through some hidden element. I need to get it being at the button level from the upper objects.


Solution

  • OK. I have found it -- use NamingContainer:

        ASPxButton btn = sender as ASPxButton;
        GridViewDetailRowTemplateContainer clsdetail = btn.NamingContainer as GridViewDetailRowTemplateContainer;
        Control gvClasses = clsdetail.Grid;  // the grid 2
        Debug.Assert(gvClasses.ClientID.EndsWith("gvClasses"));
        GridViewDetailRowTemplateContainer partitionsdetail = gvClasses.NamingContainer as GridViewDetailRowTemplateContainer;
            // the upper is the detail row of the grid 1
    
        string partition = partitionsdetail.KeyValue.ToString(); // from grid 1
        string cls = clsdetail.KeyValue.ToString();              // from grid 2