开发者

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

开发者 https://www.devze.com 2023-01-05 20:17 出处:网络
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 w

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)"

                               开发者_如何学Python     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


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


I'm setting the DataSource at Runtime but i do not call DataBind method, because it makes BeforePerformDataSelect of the Detail Grid to perform more than one.

This code set the master grids datasource and bind it:

protected void gv_Answers_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {

        ConfPrmMTempCollection _ConfPrmMTempCollection = new ConfPrmMTempCollection();
        masterKey = e.Parameters;

        if (masterKey != "")
        {
            man.Add(new SqlOperatorEquality("MAND_CONF_PRM_M_TEMP.PARAMETER_M_TEMP_ID", Convert.ToInt32(masterKey)));
            gv_Answers.DataSource = gc.LoadCollectionFromCollType(typeof(ConfPrmMTempCollection),man);
            gv_Answers.DataBind();

            man.Clear();

        }
    }

And this code is for setting the datasource of the detail grid:

protected void gv_ParameterTempD_BeforePerformDataSelect(object sender, EventArgs e) {

        ASPxGridView detailGrid = sender as ASPxGridView;

        masterKey = detailGrid.GetMasterRowKeyValue().ToString();
        man.Add(new SqlOperatorEquality("MAND_CONF_PRM_D_TEMP.PARAMETER_M_TEMP_ID", Convert.ToInt32(masterKey)));

        detailGrid.DataSource = gc.LoadCollectionFromCollType(typeof(ConfPrmDTempCollection),man);
    }


I see that you set the master grid's DataSource in the CustomCallback event handler. Try to cache the masterKey value in a Session variable and set the grid's DataSource not only in the CustomCallback event handler but also in the Page_Init method:

protected void Page_Init(object sender, EventArgs e) {
    if(Session["masterKey"] == null)
      return;
    ConfPrmMTempCollection _ConfPrmMTempCollection = new ConfPrmMTempCollection();

            masterKey = Session["masterKey"].ToString();

            if (masterKey != "")
            {
                man.Add(new SqlOperatorEquality("MAND_CONF_PRM_M_TEMP.PARAMETER_M_TEMP_ID", Convert.ToInt32(masterKey)));
                gv_Answers.DataSource = gc.LoadCollectionFromCollType(typeof(ConfPrmMTempCollection),man);
                man.Clear();
            }

    }


    protected void Page_Load(object sender, EventArgs e) {
                gv_Answers.DataBind();
    }

Does this help?


I have created a sample project based on your description and it works fine. It is available to download from:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消