Define a method and take the value in the database as a parameter

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.