我在 ASP.NET 上的 gridview 上显示数据时遇到问题。
这是我的网格视图
<asp:GridView ID="grvConsumptions" runat="server" AllowSorting="true"
AllowPaging="true" AutoGenerateColumns="false" RowStyle-CssClass="txtB"
DataKeyNames="idConsumption" PageSize="30" Width="100%" CssClass="borders"
HeaderStyle-CssClass="subT" AlternatingRowStyle-CssClass="txtA"
onpageindexchanging="grvConsumptions_PageIndexChanging"
onsorting="grvConsumptions_Sorting">
<PagerStyle HorizontalAlign="Right" CssClass="subT" />
<EmptyDataTemplate>
<asp:Literal runat="server" ID="ltNoInformationFound">
No Data Found
</asp:Literal>
</EmptyDataTemplate>
<Columns>
<asp:BoundField HeaderText="ID" ReadOnly="true" DataField="idConsumption" SortExpression="idConsumption" HtmlEncode="False" />
<asp:BoundField HeaderText="No. Venta" ReadOnly="true" DataField="stationSaleNumber" SortExpression="stationSaleNumber" HtmlEncode="False" />
<asp:TemplateField HeaderText="Trans">
<ItemStyle HorizontalAlign="Center">
</ItemStyle>
<ItemTemplate>
<asp:Image ID="imgPayment" runat="server" ImageUrl="images/icons/aro.gif">
</asp:Image>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Tarjeta" ReadOnly="true" DataField="cardCode" SortExpression="cardCode" HtmlEncode="False" />
<asp:BoundField HeaderText="Fecha" ReadOnly="true" DataField="dateCreated" SortExpression="dateCreated" HtmlEncode="False" />
<asp:BoundField HeaderText="Litros" ReadOnly="true" DataField="quantity" SortExpression="quantity" DataFormatString="{0:0.000}" HtmlEncode="False" />
<asp:BoundField HeaderText="Descripción" ReadOnly="true" ItemStyle-Width="5%" DataField="description" SortExpression="description" />
<asp:BoundField HeaderText="Precio Unitario" ReadOnly="true" DataField="price" SortExpression="price" HtmlEncode="False"/>
<asp:BoundField HeaderText="Importe" ReadOnly="true" DataField="total" SortExpression="total" HtmlEncode="False"/>
<asp:BoundField HeaderText="Kms" ReadOnly="true" DataField="mileage" SortExpression="mileage" HtmlEncode="False"/>
</Columns>
<HeaderStyle HorizontalAlign="Left" />
<PagerStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<EditRowStyle CssClass="txtB" />
<EmptyDataRowStyle HorizontalAlign="Center" CssClass="tboxCombo" ForeColor="DarkGoldenrod" BorderWidth="0px" />
<RowStyle CssClass="txtB" />
<HeaderStyle CssClass="subT" />
<AlternatingRowStyle CssClass="txtA" />
</asp:GridView>
这是我使用的一种简单方法。
DataTable dtConsumptions = GetData();
grvConsumptions.DataSource = dtConsumptions;
grvConsumptions.DataBind();
据我所知,我找不到调试方法并找出为什么在 gridview 上没有显示数据(它总是显示标签 No Data Found)。
我已经仔细检查了 DataTable 确实有数据,并且 gridview 请求的所有列都存在于数据表的列中。
如何解决此问题或找到为什么不显示数据的异常?