473,473 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

OnItemDataBound

A Web Form has 2 DataGrids. At any given time, only one of the
DataGrids will be visible to a user. Both the DataGrids also have
images (<img src../>) in the headers. The 1st DataGrid has 7 columns -
SL.NO., PRODUCT ID, PRODUCT NAME, DESCRIPTION, PRICE, QTY (each row
under this column has a TextBox) & a ADD TO CART link (which is
actually a EditCommandColumn). The first 6 columns are
TemplateColumns. The 2nd DataGrid has the same columns as the 1st one
but there are 2 additional columns - a Template Column TOTAL & a
ButtonColumn.DELETE. The Text of EditCommandColumn changes from ADD TO
CART to EDIT when the 2nd DataGrid is visible.

Note that in the 1st DataGrid, the headers of only the PRODUCT ID,
PRODUCT NAME, DESCRIPTION & PRICE columns are accompanied by images.
In the 2nd DataGrid, apart from the columns mentioned above, the
headers of the QTY & TOTAL columns are accompanied by images.

As you all must have guessed by now, this is a shopping cart app. When
the page loads for the first time, the 1st DataGrid displays all the
products from a database. When a product is added to the cart, the 1st
DataGrid gets hidden & the 2nd DataGrid becomes visible. The 2nd
DataGrid shows the details of the products the user has in his
shopping cart. When the 2nd DataGrid is visible, a LinkButton also
gets visible clicking which the 1st DataGrid becomes visible (so that
users can see all the items & add more items to his cart) & the 2nd
DataGrid & the just clicked LinkButton get hidden.

I am populating & binding the 1st DataGrid only when a user comes to
this page for the very first time. On other occasions, whenever the
1st DataGrid is visible, I am relying on the ViewState to display it.

The images accompanying the headers (which are actually LinkButtons)
change dpending upon how a column gets sorted. When a header is
clicked, I am using the ItemDataBound event of the DataGrid to change
the images. Both the DataGrids are sortable & execute the same
ItemDataBound event function.

If a user sorts the PRICE column ascendingly in the 2nd DataGrid &
then goes back to the 1st DataGrid, then the 1st DataGrid
automatically gets sorted by the PRICE column ascendlngly & vice-versa
(since it maintains the ViewState). I am saving the sort column & the
sort order in a Session variable.

Assume that a user is currently viewing the 1st DataGrid. He sorts the
PRODUCT NAME column descendlngly. Next he adds a product to his cart.
Now the 2nd DataGrid is visible.which is also sorted by the PRODUCT
NAME column descendingly. Next the user sorts the 2nd DataGrid by the
TOTAL column ascendingly. Then he goes back to the 1st DataGrid. Under
such circumstances, what I find is since there is no column named
TOTAL in the 1st DataGrid (which was sorted ascendingly in the 2nd
DataGrid), the 1st DataGrid remains sorted by the column which the
user had sorted just before coming to the 2nd DataGrid (which is
PRODUCT NAME descendingly in this case).

But I want that under such circumstances, the 1st DataGrid should be
sorted in the default manner (how it was sorted when the user visited
the page for the very first time). To do this, I added the following
code in the ItemDataBound event of the DataGrid:

If (DataGrid1.Visible = True) Then
If (InStr(Session("Sort"), "Total") 0) Then
CType(ea.Item.FindControl("imgProductID"), HtmlImage).Visible
= False
CType(ea.Item.FindControl("imgProductName"),
HtmlImage).Visible = False
CType(ea.Item.FindControl("imgDescription"),
HtmlImage).Visible = False
CType(ea.Item.FindControl("imgPrice"), HtmlImage).Visible =
False
End If
End If

But what I find is when I click the LinkButton (when the 2nd DataGrid
is visible) to come back to the 1st DataGrid, the ItemDataBound event
doesn't fire! Hence the above code snippet in the ItemDataBound event
doesn't get executed due to which the 1st DataGrid remains sorted by
the same column in the same order as how it was sorted before the user
came to the 2nd DataGrid (which is PRODUCT NAME descendingly in this
case)..

Now shouldn't the ItemDataBound event fire when the user comes back to
the 1st DataGrid from the 2nd DataGrid?

Mar 16 '07 #1
0 1609

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

Similar topics

1
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event...
0
by: vincent | last post by:
Hello, How do i get the last row OnItemDataBound in Datagrid or atleast the number of rows OnItemDataBound in Datagrid? thanks Vincent
0
by: ItNerd | last post by:
The following code causes two letters to be highlighted at once, so for example, if you click on Division 2 letter 'A', the letter 'A' in Division 1 is also highlighted. I want only one letter...
4
by: Anders | last post by:
Hi, I was wondering what is most efficient of the two. Is it more efficient to add server controls within the Itemtemplate and use OnItemDataBound to manipulate and databind the servercontrols. ...
2
by: jason | last post by:
i'm trying to set the commandargument property of a buttoncolumn in the DataGrid ItemBind event. it works fine in one instance, but in the latest page i've written it doesn't seem to work, and i...
2
by: Girish | last post by:
Hello all, Im wondering why my OnItemDataBound gets fired twice here. I got this sample code from somewhere online.. and when I put a break point in the method... it hits the method twice for...
1
by: rmccinc | last post by:
OK, I am running into some issues that I cant figure out a work-around. I am not going to post code cause I figured out WHY my issue is happening: -I have a datagrid, and a button that fires a...
1
by: Mikeon | last post by:
Hello! I have a problem customizing the databound controls using the OnItemDataBound event. The code below is an example of what I'm trying to do. I have a datasource and basing on the data I...
14
by: TS | last post by:
I have this custom data list control and i override the onItemDatabound event. After upgrading to vs 2005, this event is not always getting called, though it does at other times. No changes were...
0
by: Brian Lowe | last post by:
I'm in a web page and I have hierarchical data so I'm using 2 nested DataList controls. DataList1 is using a data source with rows of , , and where MoreData is a list. DataList1 has an...
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,...
1
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
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.