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

Determining whether the current item is the last one from inside ItemDataBound

I have a control that I want displayed in all items except the last one. I
figured the best way to do this was to determine whether the current item
was the last from within the ItemDataBound event using code such as the
following:
If e.Item.ItemIndex=(numberofitems-1) Then mycontrol.Enabled=False
but I cannot find a property that contains the total number of items before
the ItemDataBound event is raised. Any ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
May 21 '06 #1
5 3721
Nathan,

In almost all collection there is a count or a length telling what is the
total number of the items

The count-1 or lenght - 1 is than the index to the last.

I hope this helps,

Cor

"Nathan Sokalski" <nj********@hotmail.com> schreef in bericht
news:OI**************@TK2MSFTNGP04.phx.gbl...
I have a control that I want displayed in all items except the last one. I
figured the best way to do this was to determine whether the current item
was the last from within the ItemDataBound event using code such as the
following:
If e.Item.ItemIndex=(numberofitems-1) Then mycontrol.Enabled=False
but I cannot find a property that contains the total number of items
before the ItemDataBound event is raised. Any ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

May 21 '06 #2
That would help, except for one thing. What collection do I use? I tried the
following two:

DataList.DataKeys.Count
DataList.Items.Count

The problem is that these collections are not completely filled until after
the ItemDataBound event has been called however many times it gets called.
To see this, add a line such as:

Response.Write(DataList.DataKeys.Count)

inside the ItemDataBound event handler, and you will see that the value is
different each time it is called, which makes it almost useless inside this
handler. I need a property or method that can tell me the number of items
before the DataBind() method is called. I thought about using the DataTable
that I use for the DataList.DataSource property, but that would require me
to create a public or session variable, which is not the ideal way to do it,
and it requires extra code. Any other ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uh**************@TK2MSFTNGP02.phx.gbl...
Nathan,

In almost all collection there is a count or a length telling what is the
total number of the items

The count-1 or lenght - 1 is than the index to the last.

I hope this helps,

Cor

"Nathan Sokalski" <nj********@hotmail.com> schreef in bericht
news:OI**************@TK2MSFTNGP04.phx.gbl...
I have a control that I want displayed in all items except the last one. I
figured the best way to do this was to determine whether the current item
was the last from within the ItemDataBound event using code such as the
following:
If e.Item.ItemIndex=(numberofitems-1) Then mycontrol.Enabled=False
but I cannot find a property that contains the total number of items
before the ItemDataBound event is raised. Any ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


May 21 '06 #3
Nathan,

I always use the datasource to get the total items.

Be aware that you take the defaultview if you use that, which by instance in
a sort becomes than dynamic.

Cor

"Nathan Sokalski" <nj********@hotmail.com> schreef in bericht
news:e4**************@TK2MSFTNGP05.phx.gbl...
That would help, except for one thing. What collection do I use? I tried
the following two:

DataList.DataKeys.Count
DataList.Items.Count

The problem is that these collections are not completely filled until
after the ItemDataBound event has been called however many times it gets
called. To see this, add a line such as:

Response.Write(DataList.DataKeys.Count)

inside the ItemDataBound event handler, and you will see that the value is
different each time it is called, which makes it almost useless inside
this handler. I need a property or method that can tell me the number of
items before the DataBind() method is called. I thought about using the
DataTable that I use for the DataList.DataSource property, but that would
require me to create a public or session variable, which is not the ideal
way to do it, and it requires extra code. Any other ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uh**************@TK2MSFTNGP02.phx.gbl...
Nathan,

In almost all collection there is a count or a length telling what is the
total number of the items

The count-1 or lenght - 1 is than the index to the last.

I hope this helps,

Cor

"Nathan Sokalski" <nj********@hotmail.com> schreef in bericht
news:OI**************@TK2MSFTNGP04.phx.gbl...
I have a control that I want displayed in all items except the last one.
I figured the best way to do this was to determine whether the current
item was the last from within the ItemDataBound event using code such as
the following:
If e.Item.ItemIndex=(numberofitems-1) Then mycontrol.Enabled=False
but I cannot find a property that contains the total number of items
before the ItemDataBound event is raised. Any ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/



May 21 '06 #4
Why don't you use rather the PreRender event, where all items and the Items
collection are already fully built?

Eliyahu

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:OI**************@TK2MSFTNGP04.phx.gbl...
I have a control that I want displayed in all items except the last one. I
figured the best way to do this was to determine whether the current item
was the last from within the ItemDataBound event using code such as the
following:
If e.Item.ItemIndex=(numberofitems-1) Then mycontrol.Enabled=False
but I cannot find a property that contains the total number of items
before the ItemDataBound event is raised. Any ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

May 21 '06 #5
Thanks, I don't think that idea ever occurred to me because I have never
used the PreRender event before, but I think that the fact that the
condition is only true for one item, it is definitely more efficient.
Thanks!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OS**************@TK2MSFTNGP05.phx.gbl...
Why don't you use rather the PreRender event, where all items and the
Items collection are already fully built?

Eliyahu

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:OI**************@TK2MSFTNGP04.phx.gbl...
I have a control that I want displayed in all items except the last one. I
figured the best way to do this was to determine whether the current item
was the last from within the ItemDataBound event using code such as the
following:
If e.Item.ItemIndex=(numberofitems-1) Then mycontrol.Enabled=False
but I cannot find a property that contains the total number of items
before the ItemDataBound event is raised. Any ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


May 21 '06 #6

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

Similar topics

3
by: MattB | last post by:
I swear I've made this work no problem before and I'm not sure what's gone wrong. I have a form with a datagrid that I'm binding to a DatTable I generate on the fly. If I just bind and load the...
3
by: Big Dave | last post by:
I know it's been asked a million times before, but I still can't seem to find an answer that works. I've got a dropdown list in the footer template of a datagrid. The dropdown list databinds,...
5
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
5
by: Nathan Sokalski | last post by:
I want to access the DataRow used in DataBinding from the ItemDataBound event. In my case, the reason for doing this is to determine whether I need to make a word singular or plural. How can I do...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
5
by: Nathan Sokalski | last post by:
I have a control that I want displayed in all items except the last one. I figured the best way to do this was to determine whether the current item was the last from within the ItemDataBound event...
4
by: =?Utf-8?B?SmFtZXMgR2V1cnRz?= | last post by:
On my page, I have one repeater that contains a literal control and a nested repeater. The nested repeater contains a literal control. Both repeaters are databound with only one object (string). ...
1
by: Nathan Sokalski | last post by:
I need to access one of the columns from the current DataItem in the ItemCommand event, which I call using EventBubbling with a DataList and Button control. The code I tried to use to access the...
6
by: =?Utf-8?B?U2FuZHBvaW50R3V5?= | last post by:
In the datagrid I would put key values (that I didnt want to display) in columns marked not visible, in the gridview I would put them in datakeys. Im need to apply greater control over my html, so...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...

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.