复制代码 代码如下:
<ext:Grid runat="server" EnableCheckBoxSelect="false" EnableRowNumber="true"
Title="用户管理" AllowPaging="True"
onpageindexchange="gridEcUser_PageIndexChange" PageSize="10"
onrowdatabound="gridEcUser_RowDataBound" DataKeyNames="UserId">
<Toolbars>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="添加" Icon="Add">
</ext:Button>
<ext:ToolbarSeparator runat="server">
</ext:ToolbarSeparator>
<ext:Button runat="server" Text="首页" Icon="House">
</ext:Button>
</Items>
</ext:Toolbar>
</Toolbars>
<Columns>
<ext:BoundField HeaderText="用户ID" Hidden="true" DataField="UserId" ColumnID="UserId" />
<ext:BoundField HeaderText="姓名" ExpandUnusedSpace="True" DataField="FullName" ColumnID="FullName" />
<ext:BoundField HeaderText="登陆用户名" DataField="LoginName" ColumnID="LoginName" />
<ext:BoundField HeaderText="用户组" ColumnID="RolesFullName" DataField="RolesFullName" />
<ext:CheckBoxField HeaderText="用户状态" ColumnID="IsOpen" DataField="IsOpen" />
<ext:LinkButtonField HeaderText="" ColumnID="ModiUser" Text="修改" CommandName="Modi" />
<ext:LinkButtonField HeaderText="" 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='https://www.jb51.net/Images/png-0010.png'";
else e.Values[4] = "<img src='https://www.jb51.net/Images/png-0012.png'";
}
Grid中列内容居中的方法:
复制代码 代码如下:
<ext:BoundField HeaderText="姓名" ExpandUnusedSpace="True" DataField="FullName" ColumnID="FullName" DataFormatString="<div>{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")//删除
{
}
}
您可能感兴趣的文章: