简体   繁体   English

绑定数据库中的数据时如何更改值?

[英]How can I change the value at the time of binding the data from database?

I want to change the text/value of a cell in certain condition in GridView. 我想在GridView中的某些条件下更改单元格的文本/值。

I have a cell that return 'P', 'A', 'R' when I bind the Gridview from database. 当我从数据库绑定Gridview时,我有一个单元格返回“ P”,“ A”,“ R”。 I want to show the 我想展示

'Pending' in case of 'P',
'Approved' in case of 'A' and 
'Rejected' in case of 'R'

How can I change the value at the time of binding the data from database? 绑定数据库中的数据时如何更改值?

Try this 尝试这个

select (case when name='p'  then 'pending' when name='A' then 'Approved' else 'rejected' end) as a from dbo.student

name is your columnname
student is table name

Use linq to dataTable. 使用linq来dataTable。

Just store dataTable which come for your GridView datasource, and apply your changes with logic queries, which going to much easy and than assign it to GridView datasource... 只需存储用于GridView数据源的dataTable,然后将更改应用于逻辑查询即可,这比将其分配给GridView数据源要容易得多。

Second we can solve bu handling onDataBound even, but first idea is much batter... 其次,我们甚至可以解决bu处理onDataBound的问题,但是第一个想法是很多面子...

Problem will be solved.... 问题将解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM