嗨我有数据库,我将工作日保存为数字(例如星期日为1周一为2,依此类推)。我将此信息绑定到网格视图。我想要做的是当我想要在网格视图中显示工作日而不是1234567它应该显示为“SMTWThFSa”。我正在尝试案例查询,但后来我必须进行几个案例查询,例如
从Wc_Batches中选择(当Weekdy ='12'然后'SM'结束时的情况)作为Weekdy,其中BatchID ='B03141'
有人可以帮我这个。感谢。
答案 0 :(得分:0)
我认为它应该在代码级别而不是SQL中完成。将SQL查询更改为:
select Weekdy from Wc_Batches
在ascx / aspx中添加GridView
:
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Days" HeaderText="Week days" />
</Columns>
</asp:GridView>
然后在代码后面写:
var weekdays = GetWeekdays(); // some method that executes sql query and returns list.
var dataList = weekdays.Select(d => new
{
Days = string.Join(string.Empty, d.Select(c => GetWeekDayFromInt(int.Parse(c.ToString())))))
});
gv.DataSource = dataList;
gv.DataBind();
...
public string GetWeekDayFromInt(int day)
{
switch (day)
{
case 1:
return "S";
case 2:
return "M";
case 3:
return "T";
... // other days
}
return string.Empty;
}