Aspxgridview Usage Summary

Source: Internet
Author: User

A. Aspxgridview appearance Display Properties: Caption The title of the----column ( keyfieldname----Database fields seofriendly whether to enable search engine optimization Summary Specify the format of the paging 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 the header column header Settingsbehavior.allowsort whether the column header can be sorted after it is clicked Settingspager.showemptydatarows=true, when the data behavior is empty, displays the total number of records displayed for the blank row settingspager.pagesize per page Allbutton.text the "All data Display" button's text allbutton.visible whether the "All data Display" button is displayed firstpagebuotton/lastpagebutton/nextpagebutton/ prevpagebutton/corresponding to the first page, the last page, next pages, previous pages, set ibid. Numericbuttoncount minimum value is 1, control page number display number protected void aspxgridview1_pageindexchanged (object sender, EventArgs e) {DataBind ( )///Simply rebind the data to enable 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 protected void aspxgridview1_focusedrowchanged is viewed ( 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 bind 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 aspxgridview1.databind () of the grid; Perform binding 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 deleting 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: Settingsbehavior. ==> confirmdelete=true settingstext ==> confirmdelete= The string to prompt Five. Update take the value with E. newvalues[index] And remember to update the data 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. Re-bind the data in the paging pageindexchanged event 1. Dynamically add non-data bound columns, example: Dynamically add row number columnsif (! IsPostBack) {//dynamically 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 dl. propertiestextedit.displayformatstring = "C";//the format DL for displaying characters. 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.listsourcerowind Ex + 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 a foreign key field: for example, UID 2. Find these properties below Propertiescombobox: Then in the name of the customer in this column of DataSourceID, to bind it on our Word table ObjectDataSource in TextField set the field name, for example: name in 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 so it can be easily done without writing code, binding more than one table 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; The using devexpress.web.aspxeditors;//assigns a value to the Combox column when the page is loaded, where workgroupid is the field bound by 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 in the DataBound event protected void Aspxgridview1_databound (object sender, EventArgs e) {if ( aspxgridview1.visiblerowcount>0) {//aspxgridview1.columns[Command column index] (aspxgridview1.columns[4] As Gridviewcommandcolumn). Newbutton.visible = false; } }

Six. Aspxgridview FAQ A. Click the Edit or New button, delete out of update and cancel, click Update after editing the data, error: "The specified method is not supported". WORKAROUND: 1, Make sure that Aspxgridview has set Keyfieldname 2, make sure Aspxgridview has defined the event onrowdeleting, Onrowinserting, onrowupdating 3, background code has the Onrowdeleting, onrowinserting, the handling of the Onrowupdating event.
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 = Sende R as DevExpress.Web.ASPxGridView.ASPxGridView; if (grid! = null) && (dict! = null)) {int i = (int) grid. Getmasterrowkeyvalue ();/* takes the key of the main table record, the main table grid must be set keyfieldname*/if (I >= 0) {grid. DataSource = Dict . products;//to locate data by key, specify child table Data source}}}
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" >
<%--Change the caption of the button--%> function Updatecustomizationwindowvalue () {var element = document.getElementById (" Btncustwindow "); if (element = = null) return; Element.value = (grid. Iscustomizationwindowvisible ()? "Hide": "Show") + "Customization window"; <%--Displays the 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>

Tip: Aspxgridview When binding data, if the data column type is a date type, then you should use "Gridviewdatacolumn" instead of "Gridviewdatatextcolumn", so the data is displayed in the form of " 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 is a data column, although we can take advantage of <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 purpose 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 format1. 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 is the field that displays 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";// Display the link name to bind the field collink.fieldname = "Linkurl";//the Column bound field 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.