Widget |
Main data structure |
Function |
Description and main purpose |
Gridview |
Table |
ReadAndEdit |
One column per field Each field value corresponds to a cell. Display multiple records in the Network Edit Existing records |
Datalist |
Table or tree |
Read and edit |
All fields are in one cell. A cell is equal to a record. Display multiple records in the grid Create a new record in the gridview |
Repeater |
Table or tree |
Read-Only |
All fields are in one cell. A cell is equal to a record. Multiple records are displayed in the grid. Create new records for the gridview |
Detailview |
Table or tree |
ReadAndEdit and create |
Show a single record Provide default Structure Edit Existing records Create a new record |
Formview |
Table or tree |
ReadAndEdit and create |
Show a single record No Default Structure Edit Existing records Create a new record |
Dropdownlist and ListBox |
Table or tree |
Read-Only |
List Fields Allow users to select Display user-selected data |
Sitemappath |
Tree |
Read-Only |
Lists the names of pages between the home page and the current page. Used to determine the current site location |
Menu |
Tree |
Read-Only |
Displays the root node. You can select to expand a child node at a time. Displays the selected menu |
Treeview |
Tree |
Read-Only |
Displays the root node. You can select to expand a child node at a time. Used to display multiple subnodes at the same time |
Data Binding control comparison (Reapter\ Datalist \ gridview \ datailsview \ formview ):
1. Insert functions:
Detailsview and formview have the insert function. Other controls do not have
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.
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
4. Data presentation method:
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 andReapterYou must edit the template column. You can add textbox to the template column and specify the textbox ID 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 void datagrid1_updatecommand (Object source, XX)
{
String bkid = maid [E. Item. itemindex]. tostring (); // extract the primary key
String bktitle = (textbox) E. Item. cells [1]. controls [0]). Text; // extract user input
}
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.
2. Set the primary key:
Datalist1.datakeyfield = "bkid ";
Datagrid1.datakeyfield = "bkid ";
String [] STR = {"bkid "};
Gridview1.datakeynames = STR;
Iii. Primary Key extraction:
String bkid = datalist1.datakeys [E. Item. itemindex]. tostring (); // datalist
String bkid = maid [E. Item. itemindex]. tostring (); // DataGrid
String bkid = gridview1.datakeys [E. rowindex]. value. tostring (); // gridview
String bkid = detailsview1.datakey [0]. tostring ();
4. Search 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
5. confirm the deletion button:
protected void datalist1_itemdatabound (Object sender, datalistitemeventargs e)
{< br> If (E. item. itemtype = listitemtype. item | E. item. itemtype = listitemtype. alternatingitem)
{< br> linkbutton lbtn = (linkbutton) E. item. findcontrol ("lbtndelete");
lbtn. attributes. add ("onclick", "Return confirm ('Are you sure you want to delete it? ') ");
}< BR >}
protected void maid (Object sender, maid e)
{< br> If (E. item. itemtype = listitemtype. item | E. item. itemtype = listitemtype. alternatingitem)
{< br> linkbutton lbtn = (linkbutton) E. item. cells [3]. controls [0];
lbtn. attributes. add ("onclick", "Return confirm ('Are you sure you want to delete? ') ");
}< BR >}
Protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E)
{
If (E. Row. rowtype = datacontrolrowtype. datarow)
{
String Strid = E. Row. cells [0]. Text; // obtain the field value of the first row;
E. Row. cells [3]. Attributes. Add ("onclick", "Return confirm ('Confirm to delete \" "+ 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;
}
}