473,626 Members | 3,216 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11227
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.Enab leViewState = 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
11754
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 which one can insert and edit the table. The 'delete' button deletes the row.
2
2752
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 then the header/footer vanish into thin air. If I add the header/footer onDataBound then they disappear when I do a postback with no databinding. If I add them during PreRender, then they persist, but one of my data rows is emptied for each time I...
0
3024
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 postback set to true as I need to refresh the 2nd and 3rd list. Then clicks on Submit button which fires a custom event "FilterSubmitted". Yes this a custom control, as I will be using it in many places. I have a GridView control on the page that...
0
1880
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 GridView, accepts information via dropdowns embedded in the first row of the GridView about which incoming fields should go to which database fields, and writes the data to the database. The incoming data has an arbitrary number of columns so I create...
1
14007
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 work for my interation and I am starting to wonder if I am missing something in what that Count method should return. The data is loading perfectly into my GridView control.
12
3799
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 in my 'onpageload' in the cs file.
8
7730
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 containing a single gridview - enable paging and give enough data to page. add checkbox with auto postback enable add button with auto postback enable in the GridView1_PreRender method add the following : GridView1.HeaderRow.Enabled =
4
10999
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 to iterate thru the gridview's rows, examine the databound controls, then perform a database action. for some reason, i can't find the controls. i have a two templates: one that uses a label the other uses a textbox to display data. when the...
4
12018
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 update panel that the gridview is in. In my page render I put this so I could select a row by just clicking it. protected override void Render(HtmlTextWriter writer) {
0
8202
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8641
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8366
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8510
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2628
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.