GridView auto databinds for any Postback?

G

Guest

I'm moving from years with the datagrid to a new project, .net 2.0, using
GridView controls. Per past practice, it is often a lot easier to inject
controls (or special formatting) in RowDataBound (formerly ItemDataBound)
than to mess with complicated templates, especially for things that are
consistent across grids or columns. GridView is dumping all the nice stuff
put there during a RowDataBound event.

Ex: those "!" icons in outlook or classification (confidential) markings on
a row-by-row basis. In the datagrid, this worked not just well, but very
well. Once in the grid, it stayed in the grid, including postbacks from other
controls.

Now the GridView simplifies a lot of stuff like sorting, but it also wants
to invoke the DataBinding (and DataBound) event for any postback - a (new
item) button, a calendar, parent-child-linked-down bunch of dropdown lists,
whatever.

The GridView doesn't remember what what was done in RowDataBound - dumps
everything. Is there an easy way to not have it bind when the postback is
caused by a non-GridView control? Or force it to just re-bind everything? The
values of the bound columns are all there after postback - but that's all.

If I have to go to templates I will, but that means I can't re-use stuff in
nice objects/classes/common static methods (which way varies with use), which
is a much cleaner approach in the long run.

If anybody knows a nice shortcut, please speak up.
 
G

Guest

It sounds like the GridView property EnableViewState is set to false. By
default it is usually set to true. Set this property to true e.g.

myGridView.EnableViewState = true;

This should keep the data in the GridView on postbacks with out the need to
re-bind to the data source.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top