【发布时间】:2015-03-23 07:27:52
【问题描述】:
我在数据库中有一个表,我想以不同的方式在前端显示它。但我没有得到任何帮助来管理这个并展示不同的方式。
数据库表是:
Id Month Commodity Amount
----------------------------
1 May wheat 100
2 May rice 200
3 June wheat 400
4 July maize 100
my result :
Id Month Commodity Amount
----------------------------
1 May wheat 100
2 May rice 200
3 June wheat 400
4 July maize 100
但我想用 gridview 显示以下格式的数据:
Month wheat rice maize
--------------------------------
May 100 200
June 400
July 100
我的aspx代码:
<asp:GridView ID="grdData" runat="server">
</asp:GridView>
和 aspx.cs 代码
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
getdata();
}
}
public void getdata()
{
using (GridFormatEntities context = new GridFormatEntities())
{
var result = (from r in context.tbl_Commodity
select new
{
Id=r.Id,
Month = r.Month,
Commodity = r.Commodity,
Amount = r.Amount
}).ToList();
grdData.DataSource = result;
grdData.DataBind();
}
}
【问题讨论】:
标签: c# asp.net sql-server gridview