Aspxgridview Use Summary (DEVExpress) (This is a collection of knowledge points-from the blog Park)

Source: Internet
Author: User

One. Aspxgridview appearance Display Properties: Caption----column headings (keyfieldname----database fields seofriendly whether to enable search Engine optimization Summary Specify the format of pagination summary information

Setting node Showfilterrow=true set Quick Find function Settingsbehavior.allowfocusedrow=true highlighted row, That is, the selected row color Settingsbehavior.alldragdrop=false prohibit drag header column header Settingsbehavior.allowsort to achieve column header click on whether you can sort

Settingspager.showemptydatarows=true, when the data behavior is empty, displays the total number of records displayed per page settingspager.pagesize allbutton.text "All data display" The text of the button allbutton.visible whether the "All data Display" button firstpagebuotton/lastpagebutton/nextpagebutton/prevpagebutton/corresponding to the first, last, Next, On the page, set ibid. Numericbuttoncount minimum value is 1, control page number display number protected void aspxgridview1_pageindexchanged (object sender, EventArgs e) {dat Abind ()///Just re-bind 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 (object    sender, EventArgs e) {GetData (); } prevents a column from being edited, and the column behaves-editformsettings-visible=false code to hide Edit column additions, deletions, update buttons (aspxgridview1.columns[edit columns] 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, can be dynamically selected, only need to do so .... Other 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 filtered data, find the data way one, expand the filter list next to the column headings filter data (similar to the way Excel is filtered) 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 of the deleted int ID =convert.toint32 (e.keys[0]);//Get ID upd. Deldownfilelist (ID);//delete record from Database Uploadfilelistbind ();//data table binding}aspxgridview the deletion hint, set two attributes: Settingsbehavior. ==> confirmdelete=truesettingstext ==> confirmdelete= the string to prompt

Five. Update the value with E. newvalues[index] And remember to update the data after Aspxgridview1.canceledit ();//end Edit Status         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 of rebind 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 column if (! IsPostBack)         {            //Dynamic Add line number unbound data             Gridviewdatatextcolumn dl = new Gridviewdatatextcolumn ();             DL. Caption = "line number";            dl. FieldName = "hh";//The column is bound to a 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 is" +getclientip () + "user, is viewing the net Silver Terminal update content";           }   protected Void in the Customunboundcolumndata event Aspxgridview1_customunboundcolumndata (object sender, Aspxgridviewcolumndataeventargs e)     {         if (E.column.fieldname = = "hh" && E.isgetdata)              E.value = (e.listsourcerowindex + 1). ToString ();   } 2. The simple way to aspxcombobox a column is to have a 1.FiledName write primary table associated with this field with a foreign key field: for example, Uid2. Under Propertiescombobox, look for these properties: Then in the customer name of this column of DataSourceID, bind itThe ObjectDataSource of our Word table sets the field name in TextField, 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, Bind multiple tables   handwritten code to bind Aspxcombobox set this column's-behavior-propertiescombobox-valuestype to System.String in aspx to avoid the appearance of a ComboBox that cannot be selected  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 to add operations , E.newvalues[1]) to fetch the value of the client, for example: Model. Workgroupid = Convert.ToInt32 (e.newvalues[1]);  Note that the Combox column should be rendered first, after binding the data, the field bindings are case-sensitive, and the SELECT statement field names are exactly the same as  3. The Data summary rollup calculates the average or sum of all the Aspxgridview rows 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.visib lerowcount>0) {//aspxgridview1.columns[Command column index] (aspxgridview1.columns[4] as Gridviewcomman Dcolumn).        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 the Aspxgridview has set KeyFieldName2, that Aspxgridview has defined the event onrowdeleting, Onrowinserting, OnRowUpdating3, and background code that 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

codeprotected 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 ();            if (i >= 0)              {                               grid. DataSource = Dict. products;//locating data with key, specifying the sub-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.

Aspxgridview Use Summary (DEVExpress) (This is a collection of knowledge points-from the blog park)

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.