datagridview问题

shui8iuhs 2009-11-24 01:27:55
请教各位大侠们,我从数据库里得到的数据有一个字段是bit型的,现在到datagridview里面就是true,false。
我想要那个列的字段显示成:是/否。
这个该怎么弄哦???
请赐教,在此先谢谢啦~
...全文
114 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixiaohua1127 2009-11-24
  • 打赏
  • 举报
回复
其实用gridview里的那个多选框的视觉更好 换成是否是的视觉还不一定好
xinpanpan799 2009-11-24
  • 打赏
  • 举报
回复
5楼和10楼的回答都正确
刚才试了一下
呵呵 学习了
sharp_future 2009-11-24
  • 打赏
  • 举报
回复
select case when 字段=true then '是' when 字段=false then '否' form table

这个办法本人经常用 不错
不过 应该是这样写吧
select case 字段 when true then '是' when false then '否' end as 字段(这是别名) from table
其他的转换也可以这样写,如果想把其他数据显示成自己想要的数据
例如mysql中判断某个日期是星期几,用dayname(字段)这样显示的是英文的星期几
那就这样转换
select case dayname(字段) when '英文的星期一' then '星期一' when '英文的星期二' then '星期二' end as 字段(这是别名) from table
英文不好,所以是'英文的星期一' 呵呵
深海之蓝 2009-11-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 liherun 的回复:]
SQL也可以
SQL codeselectcasewhen 字段=truethen'是'when 字段=falsethen'否' formtable
[/Quote]
这个应该可以
zhengliyan_star 2009-11-24
  • 打赏
  • 举报
回复
<%#Eval("bit").ToString()=="true" ?"是":"否"%>
tzs2304 2009-11-24
  • 打赏
  • 举报
回复
二楼四楼都可以,也可以在绑定时写个方法转换下
lzsh0622 2009-11-24
  • 打赏
  • 举报
回复
可按下面这个思路,其他显示格式自己调整一下吧.

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == -1|| e.RowIndex==-1 ||dataGridView1[e.ColumnIndex,e.RowIndex].Value==null) return;
if (e.ColumnIndex == 1 && e.RowIndex>-1)
{
e.PaintBackground(e.CellBounds, false);

e.Graphics.DrawString((bool)dataGridView1[e.ColumnIndex,e.RowIndex].Value?"是":"否" , this.Font, Brushes.Black, new PointF(e.CellBounds.X + 8, e.CellBounds.Y + 8));
e.Handled = true;
}
}
liherun 2009-11-24
  • 打赏
  • 举报
回复
select case when 字段=true then '是' when 字段=false then '否' end as 字段 form table
liherun 2009-11-24
  • 打赏
  • 举报
回复
SQL也可以
 select case when 字段=true then '是' when 字段=false then '否' form table
shui8iuhs 2009-11-24
  • 打赏
  • 举报
回复
啊~~
有没有其他比较有效的方法哦??
xiamiking 2009-11-24
  • 打赏
  • 举报
回复
笨办法,用DataTable或者DataSet之前过滤一遍数据。
foreach(DataRow row in DataTable){
if(row["列名"]==0)
row["列名"]="否"
if(row["列名"]==1)
row["列名"]="是"
}

最后 datagridview.dataSource=dataTable
jmghoul 2009-11-24
  • 打赏
  • 举报
回复
在编辑列里可以设置 属性忘了

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧