0

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.

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
Jinmo Chong
  • 91
  • 1
  • 12
  • Wouldn't the condition be flipped? Also this definitely qualifies as data binding. Also... whats with your use of the non-generic interface? – Aluan Haddad Dec 07 '17 at 21:31
  • Aluan Haddad What do you mean by flipped? could you elaborate? Maybe I'm not familiar with data binding and might lose something else.. but in my concertn, I couldn't find anything – Jinmo Chong Dec 07 '17 at 21:34
  • I mean that you state that it is _not_ refreshing on post back and then go on to say that you tried `if (!ispostback) { someGrid.databind(); }`. That seems like a contradiction. – Aluan Haddad Dec 07 '17 at 21:47

1 Answers1

0

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

Jinmo Chong
  • 91
  • 1
  • 12