473,769 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Item s.Item.ItemInde x%>

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 9888
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.Li stItem){
((LinkButton) e.FindControl(" myLinkButton")) .LinkUrl =
e.Item.ItemInde x;
}

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:DataLis t id="DataList1" ...etc>
<ItemTemplate >
<a href='Pic.aspx? pic=somenumber' >picture</a>
</ItemTemplate>
<asp:DataLis t>

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.Ite ms.Item.ItemInd ex%>

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.itemi ndex %>'

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.Item s.Item.ItemInde x%>

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******@discu ssions.microsof t.com> wrote:
Peter,

Two ways:

1. Use '<%# container.itemi ndex %>'


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
2647
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
2055
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 table should be created or not. In order to do this, I need to have full control over the conditional logic for how items get displayed within a repeater element which I'm not seeing as possible. How can I cursor through a data set, apply...
2
1245
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
9665
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 with like a table layout and in the last column I want to have three radio buttons (for each row in repeater). The value of the radio button should be calculated from a value from the dataset. How can I do that? When I try to use a variable...
2
4911
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 answers to some of the items. Then if their are possible answers given, replace the TextBox with a populated dropdown box with those possible answers as list items in the dropdown. This cannot be done can it? I know I can do something similar...
5
3872
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 have run into a situation repeatedly with the designing factor of a datalist. Most of the time when I use a datalist I utilize the header, item, and footer templates to build a custom table. However, utilizing the simple example below you will...
6
9595
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 only print the Parent Category once, regardless of how many child items are in it. So my perfect output would look something like:
2
5691
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 controlling the relations etc. Now, what I'm wanting to do is to call a subroutine 'subroutine1' when the repeater is data bound, which I'm wanting to use to change the background colour of table cell tdCell1 depending on the value of
1
2036
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). I am trying to create a property at the parent control that sets a property in the child instances. So for example lets say I am creating a control that displays a list of hotel reservations for a group of people.
0
9583
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10210
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...
1
9990
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
9860
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
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2814
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.