在Gridview和sqlserver中存在疑问 [英] Doubt in Gridview and sqlserver

查看:59
本文介绍了在Gridview和sqlserver中存在疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在动态添加数据。现在我正在编辑数据。下面的粗体项是下拉菜单

列表是性别(值:'M',文字='男性'||值'F',文字='女性'。我想显示性别。



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.

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

推荐答案

我不知道VB.Net,但在C#中,通过内联语句,您可以使用三元运算符检查值并显示其各自的值。如果,值为'M'指定'男性',如果值为'F'则指定'女性'。 C#代码示例如下:



dr(性别)=(修剪(xRs!性别)=='M'?'男':'女性'



如果VB.Net中没有三元运算符,那么你可以使用if-else语句;
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;


这篇关于在Gridview和sqlserver中存在疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆