1

我有以下使用 dev express asp.net 网格 在此处输入图像描述

这是代码

  <div style="float: right; width: 78%">
                <dx:ASPxGridView ID="ASPxGridView1" runat="server" ClientInstanceName="ASPxGridView1"
                   AutoGenerateColumns="false" Width="100%" KeyFieldName="ID">
                    <Columns>
                          <dx:GridViewDataTextColumn  VisibleIndex="0" FieldName="CorporateName" Settings-AllowSort="False">

                        <DataItemTemplate>
                            <div style="text-align: center">
                                <dx:ASPxCheckBox ID="ListCheckBox" runat="server" CssClass="countCB">
                                    <ClientSideEvents CheckedChanged="OnSelectionChanged" />
                                </dx:ASPxCheckBox>
                            </div>
                        </DataItemTemplate>

                    </dx:GridViewDataTextColumn>


                        <dx:GridViewDataTextColumn FieldName="FacilityName" VisibleIndex="2" />
                        <dx:GridViewDataTextColumn FieldName="FacilityCode" VisibleIndex="3" />
                    </Columns>
                    <ClientSideEvents SelectionChanged="grid_SelectionChanged" />
                </dx:ASPxGridView>
            </div>

这很好用!!但我还需要分组行级别的“全选”复选框(不在标题中)。复选框能够根据公司名称选择所有行。

请看下面的截图 在此处输入图像描述

4

1 回答 1

1

如果我没记错的话,你正在寻找例如链接 -

GridView - 如何使用链接选择和取消选择组中的所有行

文章代码摘录:

@using DevExpress.Web.Mvc.UI;
@using DevExpress.Web.Mvc;
@Html.DevExpress().GridView(settings => {
settings.Name = "dxGridView";
settings.KeyFieldName = "ProductID";
settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartial" };

settings.Columns.Add("ProductID");
settings.Columns.Add("ProductName");
settings.Columns.Add("CategoryID").GroupIndex = 0;
settings.Columns.Add("Discontinued", MVCxGridViewColumnType.CheckBox);

settings.CommandColumn.Visible = true;
settings.CommandColumn.ShowSelectCheckbox = true;

settings.Settings.ShowGroupPanel = true;
settings.SetGroupRowContentTemplateContent(c => {
    var linkSelect = String.Format("<a onclick='SelectGroupedRows({0}, true);' href='javascript:void(0)'>Select All / </a>", c.VisibleIndex);
    var linkUnselect = String.Format("<a onclick='SelectGroupedRows({1}, false);' href='javascript:void(0)'>Unselect All Rows: {0}</a>", c.GroupText, c.VisibleIndex);

    var group = String.Format("{0}{1}", linkSelect, linkUnselect);
    ViewContext.Writer.Write(group);
});

settings.CustomCallback = (s, e) => {
    ASPxGridView grid = s as ASPxGridView;
    string[] data = e.Parameters.Split('|');

    int index = int.Parse(data[0]);
    bool value = bool.Parse(data[1]);
    if (data.Length == 2) {
        int startLevel = grid.GetRowLevel(index);
        int count = grid.VisibleRowCount;
        for (int i = 1 + index; i < count; i++) {
            grid.Selection.SetSelection(i, value);
            if (grid.GetRowLevel(i) <= startLevel)
                break;
        }
    }
};

}).Bind(Model).GetHtml()
于 2014-02-13T18:56:58.673 回答