Aspxgridview appearance Display

Source: Internet
Author: User
Tags bind tostring
One. Aspxgridview appearance Display
Property:
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 showfilterrow= True to set the Quick Find feature

Settingsbehavior.allowfocusedrow=true highlighted row, that is, the selected row color
settingsbehavior.alldragdrop= false prohibit dragging header column header
Settingsbehavior.allowsort whether the column header can be sorted after it is clicked
settingspager.showemptydatarows= True; Empty rows are displayed when the data behavior is empty
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
Protectedvoid 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
Protectedvoid 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;
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
Way one, expand the filter list next to the column header filter data (like 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
Protectedvoid 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
Protectedvoid 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 columns
if (! IsPostBack)
{
Dynamically adding line numbers to non-binding 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;//Set 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
Protectedvoid Aspxgridview1_customunboundcolumndata (object sender, Aspxgridviewcolumndataeventargs e)
{
if (E.column.fieldname = = "hh" && E.isgetdata)
E.value = (E.listsourcerowindex +1). ToString ();
}

2. Related Operations for Aspxcombobox columns
The easy Way is
1. Filedname writes the primary table with this field about 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

Handwritten code method to bind Aspxcombobox
Set the 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["

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.