ExtAspNet GridPanel的一般用法

成长带走的不只是时光,还带走了那些不害怕失去的勇气。谢谢那些怀疑我的人,给我成长的洗礼,让我更加孤独。

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

到此这篇关于ExtAspNet GridPanel的一般用法就介绍到这了。青春是气贯长虹,勇锐盖过怯懦,进取压倒苟安;如此锐气,弱冠后生有之,耳顺之年,则亦多见,年岁有如并非垂老,理想丢弃,方堕暮年。更多相关ExtAspNet GridPanel的一般用法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

标签: ExtAspNet GridPanel