将 GridBoundColumn 数据网格中的值显示为值文本

display value in GridBoundColumn datagrid as value text

<Columns>   
  <telerik:GridBoundColumn DataField="shift_start_time" HeaderText="Shift Start Time"
     AutoPostBackOnFilter="true" CurrentFilterFunction="Contains">
</Columns>

此列的值为"N"或"M",来自数据库。如果值为 "N",我想显示 "NIGHT";如果值为 "M",我想显示 "MORNING"。我怎样才能做到这一点?

我想使用我们用组合框做的 "value" "text" 的概念。可能吗?

可以使用Entity的方式来解决。 在您的实体中,定义一个函数:

public void MorningORNight(){

if(this.shift_start_time is "M"){DisplayField = "Morning"}
else{DisplayField = "Night"}
}

然后,您的实体中也会有一个只读字段。

    [ReadOnly]
public string DisplayField{ get;set; }

然后,在最开始,当您获取 shift_start_time、

        public string shift_start_time{
    get{ return _shiftstarttime;}
    set{_shiftstarttime = value;
 this.MorningORNight();}
    }

那么,你的gridview数据字段应该是DisplayField。 谢谢

或者,使用 ItemDataBound 事件更改文本:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    GridDataItem item = e.Item as GridDataItem;
    if(item != null)
    {
        item["shift_start_time"].Text = item["shift_start_time"].Text.ToString() == "M" ? "Morning" : "Night";
    }
}

注意:这当然需要重构:)