To obtain a data column of the current row, I have summarized the following methods in practice:
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. Generally, you can use HTML to setGridviewThe number of field columns is usually smaller than the actual number of fields in the data source, because not all fields are displayed on the page from the business logic perspective. 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 stillBased on E. Row. dataitem, the feature is to quickly obtain any field value of the data source, becauseDatabinder. Eval(). Do not write the wrong field name.
5. Convert E. Row. dataitem to custom type to implement data type.
For example:
Dsrequesttracking. tb_requesttrackingrow rtrow = (dsrequesttracking. tb_requesttrackingrow) (datarowview) E. Row. dataitem). row;
Requeststatusdropdownlist1.selectedvalue = rtrow. statusid. tostring ();
WhereDsrequesttrackingYesDsrequesttracking. XSDThe custom strong data type dataset of the file 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.