一、HTML 代码
<table style="width: 100%;"> <tr> <td> <asp:Button ID="Button1" runat="server" Text="选择账号" OnClick="Button1_Click" /> </td> <td> <asp:Button ID="Button2" runat="server" Text="选择菜单" OnClick="Button2_Click" /> </td> </tr> <tr> <td> <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" KeyFieldName="UsrID" Width="100%"> <Settings GridLines="Both" ShowGroupPanel="False" ShowFooter="True" ShowHeaderFilterButton="true" ShowGroupFooter="VisibleAlways" ShowPreview="True" ShowVerticalScrollBar="True" VerticalScrollableHeight="500" /> <SettingsBehavior AllowDragDrop="true" ColumnResizeMode="Control" AllowFocusedRow="True" AllowSort="true" /> <Columns> <dx:GridViewDataTextColumn Caption="账号" FieldName="UsrID" Name="ColUsrID" VisibleIndex="0" Width="120px"> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn Caption="姓名" FieldName="Name" Name="ColName" VisibleIndex="2" Width="100px"> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn Caption="部门" FieldName="Dep" Name="ColDep" VisibleIndex="3" Width="100px"> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn Caption="是否管理员" FieldName="Rem" Name="ColRem" VisibleIndex="4" Width="100px"> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn Caption="是否停用" FieldName="Sto" Name="ColSto" VisibleIndex="5" Width="100px"> </dx:GridViewDataTextColumn> </Columns> </dx:ASPxGridView> </td> <td> <dx:ASPxGridView ID="ASPxGridView2" runat="server" AutoGenerateColumns="False" KeyFieldName="ItemNO" Width="100%"> <Settings GridLines="Both" ShowGroupPanel="False" ShowFooter="True" ShowHeaderFilterButton="true" ShowGroupFooter="VisibleAlways" ShowPreview="True" ShowVerticalScrollBar="True" VerticalScrollableHeight="500" /> <SettingsBehavior AllowDragDrop="true" ColumnResizeMode="Control" AllowFocusedRow="True" AllowSort="true" /> <Columns> <%--;....................................................................;--%> <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" Caption="选择" Name="ColChk" Width="36px"> <HeaderTemplate> <dx:ASPxCheckBox ID="DchkAll" runat="server" ClientSideEvents-CheckedChanged="function(s,e){ASPxGridView2.SelectAllRowsOnPage(s.GetChecked());}"> </dx:ASPxCheckBox> </HeaderTemplate> <HeaderStyle HorizontalAlign="Center" /> </dx:GridViewCommandColumn> <dx:GridViewDataTextColumn Caption="菜单编号" FieldName="ItemNO" Name="ColItemNO" VisibleIndex="3" Width="120px"> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn Caption="菜单名称" FieldName="ItemDesc" Name="CoItemDesc" VisibleIndex="4" Width="200px"> </dx:GridViewDataTextColumn> </Columns> </dx:ASPxGridView> </td> </tr> </table>
二、Cs 后端代码
/// <summary> /// 获取 ItemNO 列的内容 /// </summary> /// <returns></returns> protected string GetDelID() { string delId = ""; //获取选中的记录Id List<object> lSelectValues = ASPxGridView2.GetSelectedFieldValues("ItemNO"); if (lSelectValues.Count==0) { return ""; }; for (int i = 0; i < lSelectValues.Count; i++) { delId += lSelectValues[i] + ","; } delId = delId.Substring(0, delId.LastIndexOf(',')); return delId; }