What are the differences between ASP. NET data controls and data binding controls (Reapter \ DataList \ GridView \ DatailsView \ FormView? Let's start to explain:
Comparison of ASP. NET data controls with data binding controls 1. Insert functions:
DetailsView and FormView have the insert function. Other controls do not have
ASP. NET data control-data binding control comparison 2. Template
DataList \ FormView \ Repeater three templates must be edited, while
The GridView and DetailsView templates are only available after the columns are converted into template columns.
Comparison of ASP. NET data controls with data binding controls 3. Automatic Paging
GridView, DetailsView, and FormView are both new controls in version 2.0, with built-in paging and sorting functions,
Others need to be manually defined
Comparison of data binding controls for ASP. NET data controls 4. Data presentation methods:
GridView, DataList, and Repeator are used to present multiple columns of data,
DetailsView and FormView are used to present single-column data, that is, common data details.
DataList and Reapter both need to edit the template column, while TextBox can be added to the template column, and the TextBox ID can be specified to extract user input values, however, the DataGrid and the GridView do not need to edit the template. Its editing function is automatically generated. We cannot know the ID of those text boxes, so we cannot get the user input through the ID, you can reference cells to achieve the following:
- Private VoidDataGrid1_UpdateCommand (ObjectSource, xx)
- {
- StringBkid = maid [e. Item. ItemIndex]. toString ();// Extract the primary key
- StringBktitle = (TextBox) e. Item. Cells [1]. Controls [0]). Text;// Extract user input
- }
Differences between ASP. NET data binding controls 1. Enter the editing status:
- DataList1.EditItemIndex = e. Item. ItemIndex;
- DataGrid1.EditItemIndex = e. Item. ItemIndex;
- GridView1.EditIndex = e. NewEditIndex;
- DetailsView1.ChangeMode (DetailsViewMode. Edit );// Enter the editing status
- DetailsView1.ChangeMode (DetailsViewMode. ReadOnly );// Exit the editing status
ASP. NET data binding controls actually differ. 2. Set the primary key:
- DataList1.DataKeyField = "bkid";
- DataGrid1.DataKeyField = "bkid";
-
- string[] str={"bkid"};
- GridView1.DataKeyNames = str;
Differences between ASP. NET data binding controls 3. Primary Key extraction:
- string bkid = DataList1.DataKeys[e.Item.ItemIndex].ToString();//DataList
- string bkid = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();//DataGrid
- string bkid = GridView1.DataKeys[e.RowIndex].Value.ToString();//GridView
- string bkid = DetailsView1.DataKey[0].ToString();
Differences between ASP. NET data binding controls 4. query controls:
- string bktitle = ((TextBox)e.Item.FindControl("txtTile")).Text;//DataList
- string bktitle = ((TextBox)e.Item.Cells[1].Controls[0]).Text;//DataGrid
- string bktitle = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
- string bktitle = ((TextBox)DetailsView1.Rows[1].Cells[1].Controls[0]).Text;
Note that there are two ways to search controls: (you can use the following two methods to search for each data-bound control)
1. If you know the Control ID, you can use this method.
(TextBox) e. Item. FindControl ("txtTile"). Text; // This is search
2. This method is available if you do not know the Control ID
(TextBox) e. Item. Cells [1]. Controls [0]). Text; // This is an index
Differences between ASP. NET data binding controls 5. Add confirmation to the delete button:
- Protected VoidDatalistitemdatabound (object sender, DataListItemEventArgs e)
- {
- If(E. Item. ItemType = ListItemType. Item | e. Item. ItemType = ListItemType. AlternatingItem)
- {
- LinkButton lbtn = (LinkButton) e. Item. FindControl ("Lbtndelete");
- Lbtn. Attributes. Add ("OnClick","Return confirm ('Are you sure you want to delete it? ')");
- }
- }
-
- Protected VoidMaid (object sender, maid e)
- {
- If(E. Item. ItemType = ListItemType. Item | e. Item. ItemType = ListItemType. AlternatingItem)
- {
- LinkButton lbtn = (LinkButton) e. Item. Cells [3]. Controls [0];
- Lbtn. Attributes. Add ("OnClick","Return confirm ('Are you sure you want to delete it? ')");
- }
- }
-
-
- Protected VoidGridviewdomainrowdatabound (object sender, GridViewRowEventArgs e)
- {
- If(E. Row. RowType = DataControlRowType. DataRow)
- {
- String strid = e. Row. Cells [0]. Text;// Obtain the field value of the first line;
- E. Row. Cells [3]. Attributes. Add ("OnClick","Return confirm ('Confirm deletion \""+ Strid +"\"? ')");
- // Two escape characters are used to enclose the values in the first column in quotation marks. Note that the next escape character will not be interpreted and will be placed directly;
-
- }
- }
This section describes the basic information about ASP. NET data binding controls. It is helpful for you to understand ASP. NET data binding controls.
- Interface Design Standards for ASP. NET Programming specifications
- Brief Analysis on naming rules of ASP. NET Programming specifications
- Analysis of ASP. NET programming standards and Their encoding specifications
- Test Specification Analysis of ASP. NET Programming specifications
- Introduction to the five Data Controls of ASP. NET