asp:BoundField是/否而不是true

时间:2009-12-16 10:39:37

标签: asp.net gridview boundfield

我有一个带

的数据网格
<asp:BoundField DataField="PrenotazioneEffettuata" HeaderText="Pren. Effettuate"
                        SortExpression="PrenotazioneEffettuata"  />

PrenotazioneEffettuata是一个布尔字段。

在网格中有真/假值

是否可以打印是/否而不是真/假?

感谢

1 个答案:

答案 0 :(得分:0)

您可以将其设置为模板字段并更改行数据绑定事件中的值。像...

  <ItemTemplate>
        <asp:Label runat="server" ID="lbl"> </asp:Label>
  </ItemTemplate>

背后的代码

protected void yourGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DataRow dr = ((DataRowView)e.Row.DataItem).Row;
        if(Convert.ToBoolean( dr["PrenotazioneEffettuata"]))
        {
            ((Label)e.Row.FindControl("lbl")).Text = "Yes";
        }
        else
        {
            ((Label)e.Row.FindControl("lbl")).Text = "No";
        }
    }
}
相关问题