473,387 Members | 1,481 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,387 software developers and data experts.

Maintaining Datagrid State on manipulated columns

I have a datagrid inside a user control. I use the itemcreated event
to manipulate column values. I then add those values up and place the
total in the footer of the datagrid. I have wrapped the function used
to obtain the data for this datagrid in a page.ispostback=false
condition. Everything displays accurately when an event(in the user
control) posts the page back to the server, but if a control outside
the user control posts the page back to the server my manipulated data
is missing (column data and summary info in the footer). The only
solution I have come up with is to remove the ispostback condition,
but then I take a performance hit because I have to go back to the
database on every post back. This really slows the page down. Does
anyone have any ideas??

Thank you,
Jason
Nov 18 '05 #1
2 1172
Try to set the column data and summary info in the "ItemDataBound"
instead, and don't handle the "ItemCreated" event.

The "ItemCreated" event fires every time the page is loaded.

However, because on a postback you don't rebind to your datasource,
the "ItemCreated" event is unable to retrieve the data to calculate
the data you need, and reset the column data and summary info to
blank.

If you don't handle the "ItemCreated" event, ASP.NET will just restore
the data to the datagrid from the viewstate, and thus preserve your
column data and summary info.

Tommy,

ja***@yoursolution.com (Jason) wrote in message news:<b8**************************@posting.google. com>...
I have a datagrid inside a user control. I use the itemcreated event
to manipulate column values. I then add those values up and place the
total in the footer of the datagrid. I have wrapped the function used
to obtain the data for this datagrid in a page.ispostback=false
condition. Everything displays accurately when an event(in the user
control) posts the page back to the server, but if a control outside
the user control posts the page back to the server my manipulated data
is missing (column data and summary info in the footer). The only
solution I have come up with is to remove the ispostback condition,
but then I take a performance hit because I have to go back to the
database on every post back. This really slows the page down. Does
anyone have any ideas??

Thank you,
Jason

Nov 18 '05 #2
Jason wrote:
Does anyone have any ideas??


In addition to Tommy's suggestions, you might consider skipping the
ItemDataBound event altogether if you're using a DataSet or DataTable as
the data source for your grid. The DataTable class has a Compute method
which will execute aggregate functions against rows that match the
specified filter:

dataTable.Compute("Sum(<column>)", "Qty > 0");

If there's some handling you have to perform between columns first, you
can always add a calculated column to your table like so:

DataColumn column = dataTable.Columns.Add("ExtdCost", typeof(double));
column.Expression = "Qty * Cost";

Once added, you can then sum that column as shown above. This is a lot
more efficient than ItemDataBound.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 18 '05 #3

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

Similar topics

4
by: Dave bailey | last post by:
When I execute the following code when using a dynamicall created LinkButton in a dynamically created dataGrid, the DataGrid disappears and the page I am trying to get to does not load. Can...
0
by: Dinesh Upare | last post by:
Hi, I want to fire events of Datatgrid without maintaining the view state. If I disable the ViewState then the events are not fired. The reason I don't want to maintain view state is because its...
6
by: DotNetGruven | last post by:
I have a webform that has a DataGrid on it with a RadioButtonList in each row. It is a simple On & Off. When the User Clicks on either of the RadioButtons, I need to postback to the server and...
0
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
2
by: Pete Moss | last post by:
During a postback event, I am having trouble retrieving the state of a CheckBox Control that I am dynamically adding to a DataGrid Control using ASP.NET 1.1. I have no trouble adding the...
4
by: gane | last post by:
Hi, I am creating datagrid bound column dynamically and need to check if a datagrid column already exists?Is there a way to check this? thanks gane
3
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
0
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,...
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...

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.