Victor
Victor

Reputation: 1108

Trouble showing data on Gridview in ASP.NET

I have been having trouble displaying data on a gridview on ASP.NET.

Here's my 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>

and this is a simple method that I used.

DataTable dtConsumptions = GetData();
grvConsumptions.DataSource = dtConsumptions;
grvConsumptions.DataBind();

To my knowledge, I can't find a way to debug and find out why data is nos displayed on the gridview (It always shows the label No Data Found).

I already double checked that the DataTable has data indeed, and that all columns that the gridview requests are present in the datatable's columns.

How can I fix this issue or find an exception of why is not displaying data??

Upvotes: 0

Views: 1016

Answers (2)

Victor
Victor

Reputation: 1108

wait, I figured it out (I still need a little bit of research though) I have an update panel: and apparentely when I press the button, it only reloads the label, but it does not reload the gridview... when I got rid of the update panel, it worked, the gridview was reloaded

Upvotes: 0

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

You can use RowDataBound event , and bind your datas on your server side with code c#;

loop about your rows and debug.

LInk : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx

Upvotes: 1

Related Questions