在GridView中将数字显示为单词 [英] Display of digits into words in gridview

查看:80
本文介绍了在GridView中将数字显示为单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想显示特定字段,以是"或否"字符串格式始终为1或0.
当将该表绑定到网格中时,所有0都应为否,而所有1则应为是.

怎么做


在此先感谢

Hi all,

I want to display particular field which will be always 1 or 0 in yes or no string format.
When binding that table into grid, all 0''s should come as No and 1''s as Yes.

How to do it


thanks in advance

推荐答案

您可以在Grid的RowDataBound 事件中轻松完成此操作.使用FindControl 方法从Gridview中找到控件并更改其值.

以下是一个示例代码,其中Student 是示例类,而Status 是字段


You can easily do it inside RowDataBound Event of Grid. Use FindControl method to find the control from Gridview and change the value.

Below is one Sample Code where Student is a sample class and Status is a field


protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Student s = (Student)e.Row.DataItem;
        if (s.Status == 1)
        {
            e.Row.Cells[2].Text = "Yes"
        }
        else
        {
            e.Row.Cells[2].Text = "false"
        }
    }
}



希望对您有帮助!



Hope this will help !!


您可以在此处打印条件格式的字符串.

就像它在网格内的标签一样

You can print conditional formatted string there.

Like if it''s Lable inside grid

Lable1.Text = i==0?"No":"Yes";



希望对您有所帮助.



Hope it helps.


这篇关于在GridView中将数字显示为单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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