473,414 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

GridView auto databinds for any Postback?

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.

--
Wesley Davis
Web Application Developer
It''s all about getting the job done
May 14 '07 #1
1 11220
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.

"Wesley Davis, General Dynamics" wrote:
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.

--
Wesley Davis
Web Application Developer
It''s all about getting the job done
May 15 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon Strandgaard | last post by:
Hi group, my setup: I have a GridView that extracts data from my table (a SqlDataSource). For each row, I have an 'edit' button and a 'delete' button. The 'edit' button opens a popup, through...
2
by: Flinky Wisty Pomm | last post by:
Hi all, I've got a really annoying problem that I need to fix sharpish. I've got a GridView derived control which has a templated header and footer. It works wonderfully on the first render but...
0
by: bsaran | last post by:
Hi, I have a code that sort of works. The event flow is as follows: In a user control of type "FilterControl" user selects certain values from 3 related dropdown lists. (two of them have auto...
0
by: yeltsin27 | last post by:
I need some advice on handling dynamically added controls in a GridView. My app takes an uploaded CSV file containing addresses, converts it to a DataTable, databinds the DataTable to a...
1
by: hartbypass | last post by:
Hello all. I am trying to interate thorugh by GridView data to pump each cell of each row into a stored proc to load to a DB. I seem to be having a heck of a time getting the Columns.Count to...
12
by: Cindy Lee | last post by:
When I do a sorta on 1 table, then the other table goes back to the original order. What can I set so, it keeps the order of the other current gridview's order. I set all the gridview values...
8
by: gerry | last post by:
The PagerSettings.Visible property is not being handled properly by the GridView control. The value assigned to this property is not applied until after a postback. Simplest test : .aspx...
4
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like...
4
by: BiffMaGriff | last post by:
Hello, I have a GridView that I put inside an update panel. I have a control that attaches to the datasource of the gridview that filters the data, databinds the gridview and then updates the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.