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

Mohammad Sepahvand picture Mohammad Sepahvand · Dec 28, 2011 · Viewed 19.1k times · Source

Can anyone explan how I can access the selected row of a detail grid in a DevExpress master-detail ASPxGridView? I've found an example on the devexpress support website But I can't get it tow ork, I'm working with version 11 of DevExpress.

Thanks in advance.

Answer

Mohammad Sepahvand picture Mohammad Sepahvand · Dec 28, 2011

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]);
    }