Search code examples
c#gridviewdata-bindingwebformsasp.net-4.5

gridview not refreshing on postback C# asp.net


I'm new to asking on stack overflow so go easy on me plz.

Using VS2012 premium edition and web forms 4.5.2.

I'm trying to update the gridview on postback.. (it updates when redirects) and I've searched a lot of articles but it only says about databind.. actually I am not databinding I'm using the selectmethod

<asp:GridView runat="server" ID="someGrid" CellPadding="10" 
    DataKeyNames="idx" AutoGenerateColumns="true"
    selectMethod="someGrid_GetData" ItemType="orders">
</asp:GridView>

and I am just calling the selectMethod on the behind.

    public IQueryable someGrid_GetData()
    {
        someContext soc = new someContext();
        var item = order.Where(s => s.idx == s.idx);
        return item;
    }

It works like a charm, but one thing.. It doesn't update when postback. I put

someGrid.databind() 

on page_load() !ispostback but it doesn't work.

It seems like an easy fix, but I've been struggling with this for hours.

Thanks in advance.


Solution

  • Oh I got it.

    @AluanHaddad was right. the data binding was working. I just thought it was not working because it didn't update when I input one data even though I was updating to the database.

    But when I input two data consequently it showed the former data.. not the most frequent one.

    The thing was, I actually had an onclick button which had a update button and I think.. (I'm not sure actually how.. )

    but the page_load event is fired before the onclick button, thus the data was not uploaded then.

    I moved the someGrid.databind() to the onclick button in the last and it works!!

    Thanks Aluan!!