473,406 Members | 2,404 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,406 software developers and data experts.

setting ItemTemplate value to DataList item index?

I have a datalist that outputs a link to a picture in each ItemTemplate:

e.g.
<asp:DataList id="DataList1" ...etc>
<ItemTemplate>
<a href='Pic.aspx?pic=somenumber'>picture</a>
</ItemTemplate>
<asp:DataList>

What I want to do is set the "pic=somenumber" querystring value
to the current DataList item's index.

e.g. something like:

Pic.aspx?pic=<%=DataList1.Items.Item.ItemIndex%>

This returns an error.

How can I retrieve the index of the current Item as it's loading the
template?
I could also create my own index value, that increments as the
DataList adds another ItemTemplate.. but not sure how to do this.

Thanks!
Peter
--

"I hear ma train a comin'
.... hear freedom comin"
Nov 18 '05 #1
3 9858
I dont have a development machine in front of me at the
moment, but I do know that a lot of other .net
databindable lists have OnItemDataBound, and OnItemCreated
events.

If it has a OnItemDataBound event, it'd be REAL easy.
throw some winforms control in the template, then you can
modify it from the code behind

if(e.ItemType == ListItemType.ListItem){
((LinkButton) e.FindControl("myLinkButton")).LinkUrl =
e.Item.ItemIndex;
}

Something along those lines. I know it works for DataGrid
and I am pretty sure data list too, but I dont think it
works with repeater.

-----Original Message-----
I have a datalist that outputs a link to a picture in each ItemTemplate:
e.g.
<asp:DataList id="DataList1" ...etc>
<ItemTemplate>
<a href='Pic.aspx?pic=somenumber'>picture</a>
</ItemTemplate>
<asp:DataList>

What I want to do is set the "pic=somenumber" querystring valueto the current DataList item's index.

e.g. something like:

Pic.aspx?pic=<%=DataList1.Items.Item.ItemIndex% >

This returns an error.

How can I retrieve the index of the current Item as it's loading thetemplate?
I could also create my own index value, that increments as theDataList adds another ItemTemplate.. but not sure how to do this.
Thanks!
Peter
--

"I hear ma train a comin'
.... hear freedom comin"
.

Nov 18 '05 #2
P.S. Per Weston's comment, I too prefer to do most things of any complexity
in the code-behind. What he suggested will work great.

"Bill Borg" wrote:
Peter,

Two ways:

1. Use '<%# container.itemindex %>'

2. Create a public function on the page that bumps and returns a static
counter, e.g. (in vb)

Private m_Num As Integer = -1
Public Function NextNum() As Integer
m_Num += 1
Return m_Num
End Function

then...

'<%# NextNum() %>'

The first is easier, the second more extensible.

hth,

Bill

"Stimp" wrote:
I have a datalist that outputs a link to a picture in each ItemTemplate:

e.g.
<asp:DataList id="DataList1" ...etc>
<ItemTemplate>
<a href='Pic.aspx?pic=somenumber'>picture</a>
</ItemTemplate>
<asp:DataList>

What I want to do is set the "pic=somenumber" querystring value
to the current DataList item's index.

e.g. something like:

Pic.aspx?pic=<%=DataList1.Items.Item.ItemIndex%>

This returns an error.

How can I retrieve the index of the current Item as it's loading the
template?
I could also create my own index value, that increments as the
DataList adds another ItemTemplate.. but not sure how to do this.

Thanks!
Peter
--

"I hear ma train a comin'
.... hear freedom comin"

Nov 18 '05 #3
On Fri, 10 Sep 2004 Bill Borg <Bi******@discussions.microsoft.com> wrote:
Peter,

Two ways:

1. Use '<%# container.itemindex %>'


That's EXACTLY what I was looking for!

Thanks to all who replied!
--

"I hear ma train a comin'
.... hear freedom comin"
Nov 18 '05 #4

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

Similar topics

3
by: Harry | last post by:
Hi, Can anyone tell me why the below code does not work. I dont get any errors, but nor does the Text for the asp:label get set. Thanks in advance as always H
3
by: Ben Becker | last post by:
I am trying to build a custom crosstab type of grid where I take some items in a data grid and based on the content of the current item compared to the previous item, determine if a new row in a...
2
by: Lerp | last post by:
Hi all, Is it possible to hide the itemtemplate when going into the edittemplate mode of a datalist? Cheers, Lerp
4
by: Emil | last post by:
Can somebody tell me what would be the syntax for having an if statement and setting the selected index of a radiobuttonlist? This is my first project using ASP.net and I use C#. I have a repeater...
2
by: Harry Simpson | last post by:
Basically have a datalist now with an itemtemplate containing a textbox for user entry and a label. The datalist is bound to a database table. My boss wants the database table to have possible...
5
by: Martman | last post by:
First here is my goal: When a datalist is rendered to a page and you use the <itemtemplate> the datalist automatically prints a <tr> <td> start and end tags. Now this may not be too bad but I...
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
2
by: mj.redfox.mj | last post by:
Hi, I wonder if someone could possibly help with this? I have the following code, which is a nested repeater in turn nesting a datalist. This all works fine, together with my page-behind vb code...
1
by: berny.zamora | last post by:
Hello everyone, I have a composite control (lets call it the parent) that contains a datalist. The datalist has an ItemTemplate that contains another composite control (lets call it the child)....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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.