We often use the Datagrid Control in projects. Some values read from the database may not be readable by users. At this time, we need to convert them,
For example, if the database contains a Sex field of the int type, "0" indicates male, and "1" indicates female, "0", "1" is in front of the user's eyes, and others may not know what it is!
Here I will share with you my solutions in the project. If you have any good solutions, please come up and let us learn together;
First read the ASPX code:
Code
<Form id = "form1" runat = "server">
<Div>
<Asp: GridView ID = "GridView1" runat = "server" AutoGenerateColumns = "False">
<Columns>
<Asp: BoundField DataField = "id" HeaderText = "ID"/>
<Asp: BoundField DataField = "address" HeaderText = "address"/>
<Asp: BoundField DataField = "name" HeaderText = "name"/>
<Asp: TemplateField HeaderText = "id">
<ItemTemplate>
<% # Comm. Util. getType (Eval ("address"). ToString () %>
</ItemTemplate>
</Asp: TemplateField>
</Columns>
</Asp: GridView>
</Div>
</Form>
Next, let's take a look at this specific class. I write this class as a DLL and have a Static method, which makes it easier for us to develop in the project; Code
Namespace Comm
{
Public class Util
{
Public static string getType (string strType)
{
Switch (strType)
{
Case "Sichuan ":
Return "sichuan ";
Case "df ":
Return "fdsa ";
}
Return strType;
}
}
}
It's that simple. Here I want to see if there are any other solutions in the garden. If there are any solutions that cannot be found in the garden, please leave a message for your solution. Thank you.