欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ExtAspNet GridPanel的一般用法

程序员文章站 2024-03-08 21:53:16
复制代码 代码如下:
复制代码 代码如下:

<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")//删除
{
}
}