【发布时间】:2014-01-22 15:59:58
【问题描述】:
我需要一些帮助, 我正在使用网格视图
<asp:GridView ID="gridMatrizes" runat="server" AutoGenerateColumns="true" AllowPaging="true"
OnRowDataBound="gridMatrizes_RowDataBound" OnRowCommand="gridMatrizes_RowCommand" OnPageIndexChanging="gridMatrizes_PageIndexChanging"
PageSize="20" class="table table-bordered table-striped table-hover ">
<Columns>
</Columns>
<PagerSettings Mode="Numeric" PageButtonCount="20" Position="Bottom" />
<PagerStyle CssClass="center" VerticalAlign="Bottom" HorizontalAlign="Center" />
</asp:GridView>
并在代码隐藏中生成列:
qsBll qsBll = new qsBll();
BaseRequest<Model.Propriedades> request_propriedades = new BaseRequest<Model.Propriedades> { };
var response = qsBll.Select_Propriedade(request_propriedades).Items;
foreach (var item in response)
{
BoundField bfield = new BoundField();
bfield.HeaderText = item.Propriedade;
bfield.DataField = item.Propriedade;
gridMatrizes.Columns.Add(bfield);
}
所以我需要从我的数据库中获取所有值并放入相关的标题中...... 例如,我的数据库是这样的:
Matriz_id Propriedade Valor_id
1 Codigo 1
我需要将“Codigo”放在标题中,并将值 1 放在数据绑定字段中。
1 Sabor 4
如果我的 Matriz_id 在数据库中有 9 个值,我的 gridview 将有 9 个列,如果它有 2 个它将有 2 个列,依此类推... 我尝试作为支点或创建列表,但我失败了......
【问题讨论】:
标签: c# asp.net gridview pivot-table anonymous-types