0

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??

7
  • For Debugging: remove Columns tag and everything inside it. AutoGenerateColumns="false" to AutoGenerateColumns="true" Then what do you see? Commented Mar 13, 2013 at 16:33
  • at what event you are binding the data? Commented Mar 13, 2013 at 16:36
  • nothing... still No Data Found Commented Mar 13, 2013 at 16:37
  • Where are you binding the GridView? Page_Load? Commented Mar 13, 2013 at 16:42
  • apparentely I use that method When Page Load, and it shows No Data Found (because at that moment the datatable doesnt get any rows, so it's correct so far), then I have a button where I can do a more advanced search and when I press it (it returns a datatable with rows, and it does pass by that method), however it does not reload the gridview (I noticed that when I decided to get rid of the method at the Page Load), so apparentely it only does not reload the gridview when I press the button =S Commented Mar 13, 2013 at 16:42

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.