Aspxgridview Usage Summary

Source: Internet
Author: User

Summary of my Aspxgridview use A. Aspxgridview appearance Display
Properties:
Caption The title of the----column ( keyfieldname----Database fields seofriendly whether search engine optimization is enabled
Summary specifying the format of pagination summary information

setting node's showfilterrow=true settings Quick Find feature Settingsbehavior.allowfocusedrow=true highlighted row, that is, the selected row color
Settingsbehavior.alldragdrop=false prohibit dragging header column headers
Settingsbehavior.allowsort whether the column header can be sorted after it is clicked
Settingspager.showemptydatarows=true When the data behavior is empty, blank lines are displayed
Settingspager.pagesize the total number of records displayed per page
Allbutton.text the text of the "All Data Display" button
Allbutton.visible whether the show all data display button
firstpagebuotton/lastpagebutton/nextpagebutton/prevpagebutton/corresponding to the first page, the last page, next pages, previous pages, set ibid.
Numericbuttoncount minimum value of 1, control page number display number
protected void Aspxgridview1_pageindexchanged (object sender, EventArgs e)
{
DataBind ()///Simply rebind the data to make the page up and down
}
The new column defaults to the Gridviewdatatextcolumn type, and you can change the way you edit new or modified columns by selecting the Change to column type of the toolbar.
Set the date type display format in the "behavior" propertiesdateedit--displayformatstring--for example: {0:yyyy mm month}

When the show Group panel is selected, the Focusedrowchanged event, the data is re-bound, the row is selected first, and then the view
protected void Aspxgridview1_focusedrowchanged (object sender, EventArgs e)
{
GetData ();
}
prevents a column from being edited, and the column behaves-editformsettings-visible=false Add, delete, update buttons for hidden edit columns in code (aspxgridview1.columns[Edit column] as Gridviewcommandcolumn). Newbutton. visible= true; (aspxgridview1.columns[Edit column] as Gridviewcommandcolumn). Deletebutton.visible = true; (Aspxgridview1.columns[8] as Gridviewcommandcolumn). UpdateButton. visible= true; each row has a checkbox that can be dynamically selected, just like this <Columns>
<dx:gridviewcommandcolumn Showselectcheckbox = "true"visibleindex= "8" &GT;&LT;/DX:GRIDVIEWCOMMANDCOLUMN&GT; Other columns </Columns>
Two. Aspxgridview binding Data
Aspxgridview1.keyfieldname = "ID";//Specify Primary key. The direct update data and child table bindings need to be used

Aspxgridview1.datasource = dt.defaultview;//Specifies the data for the grid
Aspxgridview1.databind (); Performing bindings
Note that if the query result field has an alias, the Unboundtype should be set to object when you edit the field
three. Aspxgridview Find filter data, find data

Mode one, expand the filter list next to the column headings filter data (similar to Excel filtering) Grid.Settings.ShowHeaderFilterButton = true; the filter list lists all the data that appears in the column. You can also customize the contents of the filter list, using see: Http://demos.devexpress.com/ASPxGridViewDemos/Filtering/HeaderFilter.aspx

Mode two, in the column header display field filter condition input box grid. Settings.showfilterrow = true; Displays the conditional judging mode drop-down list grid. Settings.showfilterrowmenu = true;



Four delete data
protected void Aspxgridview1_rowdeleting (object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
{
E.cancel = true;//Otherwise, only refresh the page to see the result after the deletion
int ID =convert.toint32 (e.keys[0]);//Get ID
Upd. Deldownfilelist (ID);//delete records from database
Uploadfilelistbind ();//Data table binding

}
Aspxgridview with the delete prompt, set two properties can:
Settingsbehavior. ==> Confirmdelete=true
Settingstext ==> confirmdelete= The string to prompt
Five. Update
Take the value with E. newvalues[Index]
And remember to update the data after Aspxgridview1.canceledit ();//End Edit State
E.cancel = true;
Bind ();
Example://Update
protected void Aspxgridview1_rowupdating (object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
Bill.message m = new Bill.message ();

Take the value with E. newvalues[Index]
String id = convert.tostring (e.keys[0]);
String event_date = E.newvalues[1]. ToString ();
String event_title = E.newvalues[2]. ToString ();
String event_description = E.newvalues[3]. ToString ();
string tag = E.newvalues[4]. ToString ();
M.message_update (ID, event_date, event_title, event_description, tag);

Aspxgridview1.canceledit ();//End Edit State
E.cancel = true;
Bind ();
}
Six sort
Rebind the data in the Beforecolumnsortinggrouping event
Seven. Paging
Re-bind the data in the PageIndexChanged event
1. Dynamically add non-data bound columns, example: Dynamically add row number columnsif (! IsPostBack)
{//Dynamic add line number unbound data
Gridviewdatatextcolumn dl = new Gridviewdatatextcolumn ();
Dl. Caption = "line number";
Dl. FieldName = "hh";//The column is bound to the field HH
Dl. Unboundtype = devexpress.data.unboundcolumntype.string;//non-data binding type is character type
Dl. propertiestextedit.displayformatstring = "C";//Display character format
Dl. PropertiesTextEdit.FocusedStyle.ForeColor = System.Drawing.Color.Red;
Dl. Visibleindex = 0;//Sets the index position of the row number column
ASPxGridView1.Columns.Insert (0, DL);//insert Row number column before 0


GetData ();
aspxgridview1.caption = "IP for" +getclientip () + "user, is viewing the net Silver Terminal update content";

In the Customunboundcolumndata event protected void Aspxgridview1_customunboundcolumndata (object sender, Aspxgridviewcolumndataeventargs e)
{
if (E.column.fieldname = = "hh" && E.isgetdata)
E.value = (E.listsourcerowindex + 1). ToString ();
The simple way to do this for a 2.ASPxComboBox column is to have a 1.FiledName write primary table associated with this field with the Foreign key field: for example, UID
2. Look for these properties below Propertiescombobox:
Then in the name of the customer in this column of DataSourceID, to bind it to the ObjectDataSource of our word list
Set the field name in TextField, for example: Name
The Valuefield setting name should be the primary key of the Word table (that is, the foreign key of the main Table reference Word table), for example: UID
This makes it easy to do without writing code and binding multiple tables The method of the handwritten code to bind Aspxcombobox in ASPX-propertiescombobox-valuestype the column's-behavior to System.String prevent the ComboBox from appearing unchecked using DevExpress.Web.ASPxGridView;
Using DevExpress.Web.ASPxEditors; When the page loads, assign a value to the Combox column, where workgroupid is the field bound to the Combox column in Aspxgridview
(aspxgridview1.columns["Workgroupid"] as Gridviewdatacomboboxcolumn). Propertiescombobox.valuetype = typeof (int);

Fangqm.Netbank.Core.groupInfo Group = new Fangqm.Netbank.Core.groupInfo ();
DataTable dt = Group.groupselectall ();//table
for (int i = 0; i < dt. Rows.Count; i++)
{
int id = convert.toint32 (dt. Rows[i][0]);
String v= dt. ROWS[I][1].                ToString (); (aspxgridview1.columns["Workgroupid"] as Gridviewdatacomboboxcolumn). PROPERTIESCOMBOBOX.ITEMS.ADD (New Listedititem (V, id));

} When the table is updated, the add operation, E.newvalues[1]) can be taken to the client's value, for example: Model. Workgroupid = Convert.ToInt32 (e.newvalues[1]); Note that the Combox column should be rendered first, after binding the data, and the field bindings are case-sensitive and identical to the SELECT statement field names 3. Data summary

Calculates the average or sum of all the rows of Aspxgridview and displays them in the footer.

When the Settings.showfooter property is set to True, the footer is displayed.

The summary entry for Aspxgridview is placed in the Totalsummary attribute. Set DisplayFormat For example: total {0] terminal,

Set FieldName as a non-bound field, and Summarytype set to sum indicates that the column is computed and

4. Hide the edit column, protected void Aspxgridview1_databound (object sender, EventArgs e) in the DataBound event
{
if (aspxgridview1.visiblerowcount>0)
{
aspxgridview1.columns[Command Column index]
(Aspxgridview1.columns[4] as Gridviewcommandcolumn). Newbutton.visible = false;
}
}


Six. Aspxgridview Frequently Asked Questions
A. Click the Edit or New button, delete out of update and cancel, edit the data after clicking Update, error: "The specified method is not supported". WORKAROUND:
1, ensure that the Aspxgridview has been set up Keyfieldname
2. Ensure Aspxgridview has defined event onrowdeleting, onrowinserting, onrowupdating
3, backstage code in the Onrowdeleting, onrowinserting, onrowupdating event processing.

2. Binding master/Slave table (IList)

The list element has a list property (Category.products) and needs to be displayed in a grid-nested manner.

1, select the GridView (Gird1), the right-click menu select "Edit Template"-"detailrow", the page opens the detail interface, to detailrow add a new Aspxgridview (GRID2) display detail data, You can set columns related properties for GRID2. Grid2.SettingsDetail.IsDetailGrid = True to specify Grid2 as the table data table.

2. Increase Grid2 DataBinding event

Code
protected void Grid2_databinding (object sender, EventArgs e)
{
DevExpress.Web.ASPxGridView.ASPxGridView Grid = sender as DevExpress.Web.ASPxGridView.ASPxGridView;
if (grid! = null) && (dict! = null))
{
int i = (int) grid. Getmasterrowkeyvalue ();/* Take the key of the main table record, the main table grid must be set keyfieldname*/
if (i >= 0)
{
Grid. DataSource = Dict . products;//Specifying the child table data source by locating the data with key
}
}
}

3, right click Detailrow, select "End Template Edit". Modify the Grid1. Related properties of Settingsdetail

Bool allowonlyonemasterrowexpanded default False to allow only the main table row to be expanded. True to close the last expanded detail record when the second row of detail records is expanded.

Bool Showdetailbutton Whether the detail button is displayed, True displays a "+" at the beginning of the line

Bool Showdetailrow True to display detail data

4. Filtering data

Mode one, expand the filter list next to the column headings to filter the data (similar to how Excel filters) grid. Settings.showheaderfilterbutton = true; the filter list lists all the data that appears in the column. You can also customize the contents of the filter list, using see: Http://demos.devexpress.com/ASPxGridViewDemos/Filtering/HeaderFilter.aspx

Mode two, in the column header display field filter condition input box grid. Settings.showfilterrow = true; Displays the conditional judging mode drop-down list grid. Settings.showfilterrowmenu = true;



5. User-defined column display

Grid.settingcustomizationwindow

Enabled Run Custom column display

Popuphorizontalalign column Edit window horizontal alignment

Popupverticalalign column Edit window vertical alignment



Open the column edit box via JavaScript.



Code
<script. Type= "Text/javascript" >

<%--the title of the Change button--%>
function Updatecustomizationwindowvalue () {
var element = document.getElementById ("Btncustwindow");
if (element = = null) return;
Element.value = (grid. Iscustomizationwindowvisible ()? "Hide": "Show") + "Customization window";
}
<%--Display custom Column Editing window--%>
function Showhidecustomizationwindow () {
if (grid. Iscustomizationwindowvisible ())
Grid. Hidecustomizationwindow ();
else grid. Showcustomizationwindow ();
Updatecustomizationwindowvalue ();
}
</script>
<input id= "Btncustwindow" type= "button" value= "Show Customization Window" nclick= "Showhidecustomizationwindow ();" />

<dxwgv:aspxgridview id= "Gird" .........................>
................................
<clientsideevents customizationwindowcloseup= "function (S, e) {updatecustomizationwindowvalue ();}"/>
</dxwgv:ASPxGridView>



Tips:
Aspxgridview when binding data, if the data column type is a date type, then should use "Gridviewdatacolumn" instead of "Gridviewdatatextcolumn", so that the data displayed in the format as " 1900-01-01 ", instead of" 1900-01-01 0:00:00 ".

The find control in Aspxgridview cannot be used as the FindControl in the GridView, but should be used with the Findrowcelltemplatecontrol method.

The Response.Write () method should be completely discarded in order to output characters, if the Response.Write method is called in the page, it will cause the Aspxgridview client sort function to lose control, as follows: When clicking Sort, the loading is displayed, then there is no response, and the load ing goes down and does not complete the sort operation.

When using Aspxgridviewexporter to export data from Aspxgridview, if there are data columns, though we can use
<propertiesdateedit displayformatstring= "{0:YYYY-MM-DD}" >

</PropertiesDateEdit> to format the Aspxgridview date column display style, but we have no control over the styles in the Excel file that was exported with Aspxgridviewexporter, In the exported Excel file, the date column appears in the format of the date column in the Aspxgridview data source in the database. Therefore, if you want to control the format of Excel date column after export, you must start from the Aspxgridview data source, format the date column in the data source, you can achieve the format of the exported Excel file date Columnar type purposes
Four: Export Aspxgridview data
Add a Aspxgridviewexporter control to the page, set Gridviewid to export the data Aspxgridview, call the following method to implement the export.
Aspxgridviewexporter1.writexlstoresponse ()
Aspxgridviewexporter1.writecvstoresponse ()
Aspxgridviewexporter1.writepdftoresponse ()
Aspxgridviewexporter1.writertftoresponse ()
about exporting Excel date formats, manipulating Excel, setting cells to the appropriate format
1. Traverse all data in the primary key column.

list<object> KeyValue = aspxgridview1.getselectedfieldvalues ("Kid");

String str;

foreach (Object key in KeyValue)

{

str = key. ToString ();
}
2. Select a row dynamically.

n is the number of rows to select

AspxGridView1.Selection.SetSelection (n,true);


3. Get all the data in the selection row. Here's to watch.
http://space.itpub.net/?uid-23109131-action-viewspace-itemid-676010

4. Issue: When Aspxgridview contains hyperlink buttons in a cell, Aspxgridview causes a hyperlink dislocation after sorting.

Solution: Set the properties of the hyperlink button enableviewstate=false;

5. Depending on the data of a row, the Dynamic Settings selection check box is not editable, and the row background color is set dynamically.

protected void Aspxgridview1_htmlrowprepared (Object Sender,aspxgridviewtableroweventargs e)

{

Determines whether the bomcode is empty.

if (E.getvalue ("Bomcode"). ToString (). Trim () = = "")

{

Set selection check box is not editable

E.row.cell[0]. Enabled = false;

Set the background color to light gray

E.row.backcolor = Color.lightgray;


}
}

The table has a link address, the implementation of the point link address download file, reference namespace DevExpress.Web.ASPxGridView;
If you do not want to bind dynamically, you only need to set the column's FieldName as the link Address field, textfield the field to display the link name
protected void Aspxgridview1_init (object sender, EventArgs e)
{
Gridviewdatahyperlinkcolumn Collink = new Gridviewdatahyperlinkcolumn ();//Instantiate a hyperlink column
collink.caption = "Download bar";//Set column header
ColLink.PropertiesHyperLinkEdit.Text = "This is a link";//Displays the name of the link
ColLink.PropertiesHyperLinkEdit.TextField = "linkname";//the field that displays the link name to bind
Collink.fieldname = "Linkurl";//Field bound by the column
Collink.propertieshyperlinkedit.navigateurlformatstring= "{0}";//The link address is the field bound by the column

Collink.visible = true;
Collink.width = 200;
ASPXGRIDVIEW1.COLUMNS.ADD (Collink);//Add the column to the Aspxgridview

}
Using System.Collections.Generic;

Gets the collection of current control values directly looking for the control's ID

List <object> keyvalues = this. Gridviewmethod.getselectedfieldvalues ("f_xxx");//ID of the control

foreach (Object key in KeyValues)//Loop through

{

}

2. Get a line in Aspgridview

List <object> keyvalues = this. Gridviewmethod.getcurrentpagerowvalues ("f_xxxxx");//f_xxxxx is the value of the primary key

foreach (Object key in KeyValues)//loop through the data for each column in this row

{

}

Aspxgridview Usage Summary

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.