更改数据绑定字段的显示类型. [英] Change the displayed type of a data bound field.

查看:58
本文介绍了更改数据绑定字段的显示类型.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个交叉表查询,我正在将其用作asp.gridview控件的数据源.我得到了我想要的信息,但是信息以数字方式显示,我希望将其显示为字符串.例如:
交叉表运行的表具有针对注册参加不同班级的学生的记录.每个注册记录都有一个学生ID和一个班级ID,以及一个布尔字段(出勤),如果他们参加该课程,则会设置该布尔字段.
我生成的交叉表会给我每行的学生列表和一个每个班级,出席人数的总和作为值字段.如果我运行此查询并将其设置为网格视图的数据源,则会得到几乎正是我想要的结果:

Student  Student  Student  Student   Student  Student  Student  Student  Student  Student  Student  Student  第1类Class2 Class3等等...
s1          -1       -1         0
s2           0                  -1      
s3           0       -1        -1

其中 空白表示他们从未注册过该课程(空), -1表示他们注册并参加了(true),和0表示他们已注册但未参加.

在绑定数据后,我无法更改数据列的类型,只需遍历该表即可将0和-1替换为已注册并已出席,但这就是我要实现的目标.任何人都可以想出一种快速简便的方法来达到此最终结果的方法.只要可行,我就会努力解决.

I have a crosstab query that I am using as the datasoure for an asp gridview control.  I gets me the information I want, but the information is displayed numerically and I would like it to be displayed as strings. For example:
The table the cross tab runs on has records for students that are registered to attend different classes.  Each registration record has a studentID and a classID along with a boolean field (attendance) which is set if they attended the class.
The crosstab I generate gives me a list of students in each row and a column for each class, with the sum of attendance as the value field. if I run this query and set it as the datasorce of my grid view I get this which is almost exactly what I want:

Student   Class1  Class2  Class3  etc...
s1           -1        -1          0
s2            0                    -1       
s3            0        -1         -1

where  a blank means they never registered for the class (null),  -1 means they registered and attended (true),  and 0 means they registered but did not attended.

I can't change the type of the datacolumns after the data is bound and just iterate over the table replacing the 0's and -1's with registered and attended, but that is what I would like to achieve.  Can anyone come up with a quick and easy way to achieve this end result.  I'll settle for long and difficult as long as it works.

推荐答案

感谢您的信息!我建议在( Windows开发人员中心 > http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/threads ).

Thank you for your post!  I would suggest creating a new thread for your question in the (Windows Developer Center > Windows Forms Forums > Windows Forms Data Controls and Databinding ) forum located here:  (http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/threads).

希望会有所帮助.

祝您度过愉快的一天!

感谢&问候,


这篇关于更改数据绑定字段的显示类型.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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