Change data binding results of ASP.NET DATAGRID

xiaoxiao2021-03-06  50

DataGrid After the data binding, the data is generally displayed in the database for the data to be read in the database, and the corresponding data is displayed as required by the database content, the method is as follows:

In the database, use 0 representatives are not used, 1 represents have been used, 2 is not activated, 3 is activated.

According to the simple database binding, the results displayed are 0, 1, 2, 3 and other numbers, the expression is not clear, and now change the binding display result.

Double-click the itemDatabase in the DataGrid and program it in the ItemDatabase.

Change the display result in the display list: Determine the type of itemType, you need to judge ListItemType.Item and ListItemType.alternatingItem.

The statement is as follows:

IF (E.Item.ItemType == ListItemType.Item || E.Item.ItemType == ListItemType.alternatingItem)

{

/ / Treatment here

}

Get the value of the current row using DataRowView:

DataRowView DRV = (DATAROWVIEW) E.DataItem;

Use the DRV [column name] to get the bound value, this assumptions list: Status

Assumption is displayed in the second column: E.Item.cell [2]

Programmed as follows:

Switch (R ["status"]. TOSTRING ())

{

Case "0":

E.Item.cell [1] .Text = "Nothing";

Break;

Case "1":

E.Item.cell [1] .Text = "Use";

Break;

Case "2":

E.Item.cell [1] .Text = "No activation";

Break;

Case "3":

E.Item.cell [1] .Text = "Already activated";

Break;

}

This allows the desired display result.

E.Item.itemType == ListItemType.editItem

Set the result when editing

转载请注明原文地址:https://www.9cbs.com/read-117490.html

New Post(0)