Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am dynamically adding the data. Now I am editing the data. The below bold item is dropdown
list is sex(value : 'M', Text = 'Male'|| value 'F', Text = 'Female'. I want to display the sex.

C#
If xRs.HasRows = True Then

               Dim dt As New DataTable()
               Dim dr As DataRow = Nothing
               dt.Columns.Add(New DataColumn("SI", GetType(String)))
               dt.Columns.Add(New DataColumn("Name", GetType(String)))
               dt.Columns.Add(New DataColumn("Age", GetType(String)))
               dt.Columns.Add(New DataColumn("Sex", GetType(String)))

               Do While xRs.Read()
                   RowCount = RowCount + 1
                   dr = dt.NewRow()
                   dr("SI") = RowCount
                   dr("Name") = Trim(xRs!Name)
                   dr("Age") = Trim(xRs!Age)
                   dr("Sex") = Trim(xRs!sex)  
                   dt.Rows.Add(dr)
               Loop

               ViewState("CurrentTable") = dt
               GridView01.DataSource = dt
               GridView01.DataBind()
           End If
Posted
Updated 26-Aug-13 21:52pm
v3
Comments
What is the xRs!sex?

1 solution

I have no idea about VB.Net, but in C#, through the inline statement, you can use the ternary operator to check the value and show its respective value. Like if, value is 'M' assign 'Male' and if value is 'F' assign 'Female'. Sample of C# code is as below:

dr("Sex") = (Trim(xRs!sex) == 'M' ? 'Male' : 'Female'

if ternary operator is not available in VB.Net, then you can use if-else statement;
 
Share this answer
 
Comments
Member 1233140 29-Aug-13 11:05am    
no i am using dr as datarow

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900