How to get selected row of detail grid in Master-Detail GridView?

mehmetserif picture mehmetserif · Jul 7, 2010 · Viewed 17.4k times · Source

I'm having a problem on getting the selected rows values of a detail grid. I have master-detail grid in a popup control and it works fine. I also enabled the enable selection to have checkboxes but when i try to run GetSelectedFieldValues on ClientSideEvents of a button it always returns "0". What do i do wrong, i couldn't find it?

Here is the detail grid:

                            AutoGenerateColumns="False"

CssFilePath="~/App_Themes/Aqua/{0}/styles.css"

                            CssPostfix="Aqua" 

                            OnBeforePerformDataSelect="gv_ParameterTempD_BeforePerformDataSelect"

ClientInstanceName="gvC_ParameterTempD">

                                <dxwgv:GridViewCommandColumn

ShowSelectCheckbox="True" VisibleIndex="0">

                                </dxwgv:GridViewCommandColumn>

                                <dxwgv:GridViewDataTextColumn

Caption="Detay Kodu" FieldName="PrmDetailCode"

                                    VisibleIndex="0">

                                </dxwgv:GridViewDataTextColumn>

                                <dxwgv:GridViewDataTextColumn

Caption="Seçim Adı" FieldName="PrmDetailName"

                                    VisibleIndex="2">

                                </dxwgv:GridViewDataTextColumn>

                                <dxwgv:GridViewDataTextColumn

Caption="Seçim Adı(Grup)"

                                    FieldName="PrmDetailNameG"

VisibleIndex="3">

                                </dxwgv:GridViewDataTextColumn>

                                <dxwgv:GridViewDataTextColumn

Caption="Seçim Adı(Stok)"

                                    FieldName="PrmDetailNameS"

VisibleIndex="4">

                                </dxwgv:GridViewDataTextColumn>

                                <dxwgv:GridViewDataTextColumn

Caption="Grup Seçimi Yapan"

                                    FieldName="PrmGroupSelector"

VisibleIndex="5">

                                </dxwgv:GridViewDataTextColumn>

                                <dxwgv:GridViewDataTextColumn

Caption="Stok Seçimi Yapan"

                                    FieldName="PrmStokSelector"

VisibleIndex="6">

                                </dxwgv:GridViewDataTextColumn>

                            </Columns>

And this is the button:

                <ClientSideEvents Click="function(s,e)

                {

                    pcc_Question.Hide();

                    gvC_ParameterTempD.GetSelectedFieldValues('PrmDetailName;PrmDetailNameG;PrmDetailNameS',ShowCellValue);

                }"

                />

            </dxe:ASPxButton>

and this is the jsscript:

function ShowCellValue(values) {

    var value = condition.GetText();

    alert(values.length); // here it returns "0"

    if(value != "")

    {

        var newValue = ' ' + value + values + ' = ';

        condition.SetText(newValue);

    }

    else

    {

        for(var i = 0; i < values.length; i ++) {

            value += values[i];

        }

        condition.SetText(value);

    }



}

I don't know what i do wrong,

Thanks for the help

Answer

DevExpress Team picture DevExpress Team · Jul 7, 2010

Am I right in my assumption that the button is residing in the same DetailRowTemplate container? Anyway, it is necessary to access the proper instance of the detail GridView object. To do this, set the grid's ClientInstanceName property to a dynamic value. This should allow you to access the proper grid instance and fetch selected row values. A sample code is available at:

http://www.devexpress.com/Support/Center/ViewIssue.aspx?issueid=Q90007