General Usage of extaspnet. gridpanel

Source: Internet
Author: User
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
{

}
}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.