在Page_Load上更改GridView单元格字符串

时间:2013-01-17 17:52:05

标签: c# asp.net gridview

我有一个名为Active的列的GridView,它显示1(表示活动)或-1表示非活动状态。

然而,由于这是在前端UI中实现的,我不希望向用户呈现他们看似无用的整数,但是在GridView中呈现ActiveNot activePage_Load

代码看起来像 -

protected void Page_Load(object sender, EventArgs e)
    {
        //code here to modify the column 'Active' in the GridView
        //GridView ID="GV1"

        if (row.Cells[1].Text == "1")
        {
            row.Cells[1].Text = "Active";
        }
        if (row.Cells[1].Text == "-1")
        {
            row.Cells[1].Text = "Not Active";
        }

    }

GridView中的列是 -

<asp:BoundField HeaderText="Active" DataField="Active" SortExpression="Active"></asp:BoundField>

我怎么能这样做,因为我不想编辑数据库以使UI更具可呈现性?

1 个答案:

答案 0 :(得分:2)

尝试OnRowDataBound Gridview事件。