2

Here we are again with the next problem in sorting.

this is a follow up question to this question

I have now made a type to contain the data I need. however, when I try to fetch the data FROM the gridview it returns null, which means I can't sort anything that is not there in the first place...

any ideas why this returns null ...

IEnumerable<JointServerData> data = gvServers.DataSource;
var sorted = data;
switch (p)
   {
       case "domain":
            sorted = data.OrderBy(o => o.DomainName);
            break;
       default:
            break;
    }
gvServers.DataSource = sorted;
gvServers.DataBind();

above is what I'm trying to do ...

4 Answers 4

5

Without seeing all your code I'd have to assume that this is a PostBack issue. Website's are intrinsically stateless and you need to resolve this by either caching information between page requests or retrieving the data each time.

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

Comments

5

I agree with Mark. It seems that this happens between postbacks. If so, you can't have access to grid's datasource, because after first binding and rendering this grid to html, you will receice only that html on postback, but not real datasource. You need to keep your datasource either in session or get it on every postback from database.

P.S. and sorry, guys, for my ugly English :-[

Comments

0

Try to set data binding in Init event of control.

Comments

-1

Other thing to point out is that GridView does not keep DataSource property populated over the postbacks (for performance feasons since it would need to

serialize and roundtrip the entire data source)

Teemu Keiski ASP.NET MVP, AspInsider Finland, EU

from http://bytes.com/topic/asp-net/answers/828307-gridview1-datasource-null or you use linq datasource for yor linq queries. it automatically handles sorting process.

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.