Can I convert a boolean to Yes/No in a ASP.NET GridView

前端 未结 9 1277
孤街浪徒
孤街浪徒 2020-12-22 17:17

I have a ASP.NET GridView with a column mapped to a boolean. I want do display \"Yes\"/\"No\" instead of \"True\"/\"False\". Well actually I want \"Ja\"/\"Nej\"

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-22 17:25

    You could use a Mixin.

    /// 
    /// Adds "mixins" to the Boolean class.
    /// 
    public static class BooleanMixins
    {
        /// 
        /// Converts the value of this instance to its equivalent string representation (either "Yes" or "No").
        /// 
        /// 
        /// string
        public static string ToYesNoString(this Boolean boolean)
        {
            return boolean ? "Yes" : "No";
        }
    }
    

提交回复
热议问题