ASPxGridView - How to get the Selected Row in a Detail Grid of a Master-Detail GridView?

19,522

I found a way to get the selected row of the detail grid, not sure how 'advised' it is to do it this way but it works fine for me, I added an onload() event to the detail grid and then I was able to access that instance of the gridview by casting it to an ASPxGridView.

Here is my Code, the detail grid:

<Templates>
            <DetailRow>

                <dx:ASPxGridView ID="detailGrid" runat="server"   DataSourceID="SqlDataSource2" 
                    Width="100%" OnBeforePerformDataSelect="detailGrid_DataSelect" 
                         KeyFieldName="InvoiceID"
                         EnableCallBacks="False" 
                         onload="detailGrid_Load"
                          >

and then I handle the onoad() event like this:

ASPxGridView gridView;
protected void detailGrid_Load(object sender, EventArgs e)
{

    gridView = sender as ASPxGridView;
    gridView.SelectionChanged += new EventHandler(gridView_SelectionChanged);

}

So I just made a ASPxGridView instance of the detail grid, and now I can make use of its SelectionChanged() event.

private static int invoiceID;

    void gridView_SelectionChanged(object sender, EventArgs e)
    {
        invoiceID = Convert.ToInt64(gridView.GetSelectedFieldValues("InvoiceID")[0]);
    }
Share:
19,522
Mohammad Sepahvand
Author by

Mohammad Sepahvand

Updated on July 13, 2022

Comments