我有以下使用dev express asp.net grid
这是代码
<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>
这很棒!!但是我还需要在分组行级别(不在标题中)选中“全选”复选框。选中此复选框可以根据公司名称选择所有行。
见下面的截图
答案 0 :(得分:1)
如果我没错,你正在寻找链接的例子 -
GridView - How to use the link to select and deselect all rows in a group
文章摘录:
@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()