Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > setting ItemTemplate value to DataList item index?

Reply
Thread Tools

setting ItemTemplate value to DataList item index?

 
 
Stimp
Guest
Posts: n/a
 
      09-10-2004
I have a datalist that outputs a link to a picture in each ItemTemplate:

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

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"
 
Reply With Quote
 
 
 
 
Weston Weems
Guest
Posts: n/a
 
      09-10-2004
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.
><aspataList id="DataList1" ...etc>
> <ItemTemplate>
> <a href='Pic.aspx?pic=somenumber'>picture</a>
> </ItemTemplate>
><aspataList>
>
>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"
>.
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmlsbCBCb3Jn?=
Guest
Posts: n/a
 
      09-10-2004
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.
> > <aspataList id="DataList1" ...etc>
> > <ItemTemplate>
> > <a href='Pic.aspx?pic=somenumber'>picture</a>
> > </ItemTemplate>
> > <aspataList>
> >
> > 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"
> >

 
Reply With Quote
 
Stimp
Guest
Posts: n/a
 
      09-10-2004
On Fri, 10 Sep 2004 Bill Borg <(E-Mail Removed)> 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"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting Radio Button In A Item Template Of A DataList pierre.basson@psitek.com ASP .Net 3 02-02-2005 03:03 PM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
Problem with setting background color alternating item in datalist to a certain color fig000 ASP .Net Web Controls 0 09-06-2004 06:51 PM
Getting the value from ItemTemplate of DataList Vannela ASP .Net 1 12-12-2003 02:57 PM



Advertisments