Gridview is a powerful data display control in ASP. NET. Its rowdatabound event provides us with a convenient way to control row and column data.Software Development Network www.mscto.com
To obtain a data column of the current row, you can use the following methods:
1. cells [X]. txt.
Obtain the text value from the column cell. This method is simple, advanced, and most commonly used, but with simple functions. This method has several disadvantages:
(1) the value of the data column with hidden attributes cannot be obtained. The obtained value is "" (null ).
(2) Only data columns defined in HTML can be obtained, and all field columns of the current data row in the data source cannot be queried. In general, the number of field columns in the gridview is usually smaller than the actual number of fields in the data source through HTML settings, because from the perspective of business logic, not all fields are displayed on the page. When you need to use a field that is not displayed, this method cannot directly meet the requirements.
2. E. Row. cells [X]. findcontrol ("yourcontrolname ").
This is to find a server control in a cell to obtain its data value. In this way, you can operate the server controls in cells. This method is generally used to process data or controls in the template column.
3. (datarowview) E. Row. dataitem). Row. itemarray [X]. tostring ().
The core of this method is E. Row. dataitem, which is the row dataset of the gridview, which is of the object type. After converting it to the datarowview type, more operation methods can be obtained. This dataset indicates all field columns in the current row of the data source. itemarray [x] is an array object of all field columns in the current row. You can obtain any field value through index x. This method can be used to query all fields of the data source.
4. databinder. eval (E. Row. dataitem, "yourdatafieldname"). tostring ().
This method is still based on E. Row. dataitem. It is more convenient to obtain any field value of the data source, because databinder. eval () is used, it should be noted that do not write the wrong field name.Software Development Network www.mscto.com
5. Convert E. Row. dataitem to custom type to implement data type.
example:
dsrequesttracking. tb_requesttrackingrow rtrow = (dsrequesttracking. tb_requesttrackingrow (datarowview) E. row. dataitem ). row;
requeststatusdropdownlist1.selectedvalue = rtrow. statusid. tostring ();
where dsrequesttracking uses dsrequesttracking. the XSD file is a custom strong type dataset in the project. tb_requesttrackingrow is a method that vs automatically generates for this strong type to create a data row object. This method is widely used in typed data. Data typing has many advantages. What is obvious is to pass a type of data to the method to replace a large number of parameters. In addition, the spelling of field names will no longer occur.