代码如下:
<ext:Grid ID="gridEcUser" runat="server" EnableCheckBoxSelect="false" EnableRowNumber="true"
Title="用户管理" AllowPaging="True"
onpageindexchange="gridEcUser_PageIndexChange" PageSize="10"
onrowdatabound="gridEcUser_RowDataBound" DataKeyNames="UserId">
<Toolbars>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:Button ID="btnAddEcUser" runat="server" Text="添加" Icon="Add">
</ext:Button>
<ext:ToolbarSeparator ID="ToolbarSeparator1" runat="server">
</ext:ToolbarSeparator>
<ext:Button ID="btnToHome" runat="server" Text="首页" OnClick="btnToHome_Click" Icon="House">
</ext:Button>
</Items>
</ext:Toolbar>
</Toolbars>
<Columns>
<ext:BoundField HeaderText="用户ID" Width="50px" Hidden="true" DataField="UserId" ColumnID="UserId" />
<ext:BoundField HeaderText="姓名" Width="150px" ExpandUnusedSpace="True" DataField="FullName" ColumnID="FullName" />
<ext:BoundField HeaderText="登陆用户名" Width="150px" DataField="LoginName" ColumnID="LoginName" />
<ext:BoundField HeaderText="用户组" Width="150px" ColumnID="RolesFullName" DataField="RolesFullName" />
<ext:CheckBoxField HeaderText="用户状态" Width="80px" ColumnID="IsOpen" DataField="IsOpen" />
<ext:LinkButtonField HeaderText="" Width="60px" ColumnID="ModiUser" Text="修改" CommandName="Modi" />
<ext:LinkButtonField HeaderText="" Width="60px" ColumnID="DelUser" Text="删除" CommandName="Del" ConfirmIcon="Question" ConfirmText="确认要删除用户吗?" ConfirmTitle="易彩国际" />
</Columns>
</ext:Grid>
C#代码:
复制代码代码如下:
//数据绑定:
//说明:列的DataField名称要与DataTable中的字段名称一致。
DataTable UserDt = UserBLL.GetEcUserList();
gridEcUser.DataSource = UserDt;
gridEcUser.DataBind();
代码
复制代码代码如下:
protected void gridEcUser_RowDataBound(object sender, ExtAspNet.GridRowEventArgs e)
{
DataRow Dr = e.DataItem as DataRow;
if (Dr != null)
{
bool IsOpen = Convert.ToBoolean(Dr["IsOpen"]);
if (IsOpen) e.Values[4] = "<img src='../Images/png-0010.png' style='width:16px;text-align:center'";
else e.Values[4] = "<img src='../Images/png-0012.png' style='width:16px;'";
}
Grid中列内容居中的方法:
复制代码代码如下:
<ext:BoundField HeaderText="姓名" Width="150px" ExpandUnusedSpace="True" DataField="FullName" ColumnID="FullName" DataFormatString="<div style='text-align:center;width:100%'>{0}</div>" />
Grid的RowCommand事件中获得列值:
1:在Grid的DataKeyNames中设置行关键字,如:DataKeyNames="UserId,UserName"
2:
代码
复制代码代码如下:
protected void gridEcUser_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
{
if (e.CommandName == "Modi") //修改
{
string DD = gridEcUser.DataKeys[e.RowIndex][0].ToString();
ExtAspNet.Alert.Show(DD);
}
else if (e.CommandName == "Del")//删除
{
}
}