程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> ASP.NET基礎 >> ExtAspNet GridPanel的一般用法

ExtAspNet GridPanel的一般用法

編輯:ASP.NET基礎
復制代碼 代碼如下:
<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")//刪除
{
}
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved