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"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
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"
>.
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"
On Fri, 10 Sep 2004 Bill Borg <BillBorg@.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"
0 comments:
Post a Comment