Code
<Ext: Grid id = "gridecuser" runat = "server" enablecheckboxselect = "false" enablerownumber = "true"
Title = "user management" 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 = "add" icon = "add">
</Ext: button>
<Ext: toolbarseparator id = "toolbarseparator1" runat = "server">
</Ext: toolbarseparator>
<Ext: button id = "btntohome" runat = "server" text = "Homepage" onclick = "btntohome_click" icon = "House">
</Ext: button>
</Items>
</Ext: toolbar>
</Toolbars>
<Columns>
<Ext: boundfield headertext = "User ID" width = "50px" hidden = "true" datafield = "userid" columnid = "userid"/>
<Ext: boundfield headertext = "name" width = "150px" expandunusedspace = "true" datafield = "fullname" columnid = "fullname"/>
<Ext: boundfield headertext = "Login User Name" width = "150px" datafield = "loginname" columnid = "loginname"/>
<Ext: boundfield headertext = "User Group" width = "150px" columnid = "rolesfullname" datafield = "rolesfullname"/>
<Ext: checkboxfield headertext = "user status" width = "80px" columnid = "isopen" datafield = "isopen"/>
<Ext: linkbuttonfield headertext = "" width = "60px" columnid = "modiuser" text = "modify" commandname = "Modi"/>
<Ext: linkbuttonfield headertext = "" width = "60px" columnid = "deluser" text = "delete" commandname = "Del" confirmicon = "Question" confirmtext = "are you sure you want to delete the user? "Confirmtitle =" "/> </columns>
</Ext: Grid>
C # code:
// Data binding: // Note: The datafield name of the column must be consistent with the field name in the datatable.
Datatable userdt = userbll. getecuserlist ();
Gridecuser. datasource = userdt;
Gridecuser. databind ();
Code
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] = "Else E. Values [4] = "
}
How to center column content in Grid:
<Ext: boundfield headertext = "name" width = "150px" expandunusedspace = "true" datafield = "fullname" columnid = "fullname" dataformatstring = "<Div style = 'text-align: center; width: 100% '> {0} </div> "/>
Get the column value in the rowcommand event of the grid:
1: set row keywords in datakeynames of the grid, for example, datakeynames = "userid, username"
2:
Code
Protected void gridecuser_rowcommand (Object sender, extaspnet. gridcommandeventargs E)
{
If (E. commandname = "Modi") // modify
{
String dd = gridecuser. datakeys [E. rowindex] [0]. tostring ();
Extaspnet. Alert. Show (dd );
}
Else if (E. commandname = "Del") // Delete
{
}
}