Get the App
SLTechnology News&Howtos  ›  Development  › 

How to encode and determine the corresponding value of data in the event handling of RowDataBound

Shulou Source: shulou.com Published: 2022-06-02 03:30:48 11月03日 Update

How to encode and determine the corresponding value of the data in the event handling of RowDataBound? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

When ProductsDataTable is bound to GridView,GridView, several ProductsRow will be generated. The DataItem property of GridViewRow will generate an actual ProductRow. In order to determine the value of UnitsInStock after the RowDataBound event of GridView, we need to create the event handler of RowDataBound, in which we can determine the value of UnitsInStock and format it accordingly

The creation process of EventHandler is the same as the previous two.

RowDataBound: event handling for creating the RowDataBound event of a GridView

The following code will be automatically generated in the background code

Protected void HighlightCheapProducts_RowDataBound (object sender, GridViewRowEventArgs e) {}

When the RowDataBound event is triggered, the second parameter, GridViewRowEventArgs, contains a reference to GridViewRow. We use the following code to access the ProductsRow in GridViewRow

Protected void HighlightCheapProducts_RowDataBound (object sender, GridViewRowEventArgs e) {/ / Get the ProductsRow object from the DataItem property... Northwind.ProductsRow product = (Northwind.ProductsRow) ((System.Data.DataRowView) e.Row.DataItem) .Row; if (! product.IsUnitPriceNull () & & product.UnitPrice < 10m) {/ / TODO: Highlight the row yellow... }}

When using RowDataBound event handling, GridView consists of various types of rows, and for all row types, the type of GridViewRow can be determined by the RowType property, which can be one of the following types

A record in the DataSource of DataRow-GridView

An empty behavior shown by the DataSource of EmptyDataRow-GridView

Footer-bottom line; display is determined by the ShowFooter property of GridView

Header-header line; display is determined by the ShowHeader property of GridView

Pager-GridView pagination, this line shows the markup of the paging

Separator-not available for GridView, but useful for the RowType properties of DataList and Reapter, which we will discuss in future articles

When the above four (DataRow, Pager Rows Footer, Header) are not suitable for the corresponding values, an empty data item will be returned, so we need to check the RowType property of GridViewRow in the code to determine:

Protected void HighlightCheapProducts_RowDataBound (object sender, GridViewRowEventArgs e) {/ / Make sure we are working with a DataRow if (e.Row.RowType = = DataControlRowType.DataRow) {/ / Get the ProductsRow object from the DataItem property... Northwind.ProductsRow product = (Northwind.ProductsRow) ((System.Data.DataRowView) e.Row.DataItem) .Row; if (! product.IsUnitPriceNull () & & product.UnitPrice < 10m) {/ / TODO: Highlight row yellow... } the answer to the question on how to encode and determine the corresponding value of the data in the event handling of RowDataBound is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Tags: Events attributes processing code type data questions coding one line more help generation solution different appropriate easy easy two content parameters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi Docker NVidia Microsoft