473,497 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help with repeater, how to code it in code-behind page

Tee
Hi,

I have a Repeater with a DataReader.
I can successfully let the code run with something like this
<asp:label id="testlabel" text='<%# DataBinder.Eval(Container.DataItem,
"Name") %>' runat="server"></asp:label>

but now I would like to code this few line ItemTemplate in my code-behind
page, how do I do it ?
Thanks,
Tee
Nov 18 '05 #1
1 1362
I tried to do the same thing you are doing when I first was learning asp.net I hated the idea of using <%# %> Let me just say, that using <%# %> in this case is MUCH Easier, than doing it from codebehind!

But to do it in codebehind, in the ItemDataBound event you need something like this (This is an example taken from a datagrid, a repeater should be just about the same)

If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
Dim lbl As Label = DirectCast(e.Item.Controls(0).Controls(0), Label)
lbl.text = e.Item.DataItem("Name")
End If

The tricky part which makes this more difficult is finding the right nested sequence of controls that corresponds to the label. And what makes it even more difficult, if you ever change the structure around, you'll need to change this code around.

Hope this helps
--Michael

"Tee" <th*@streamyx.com> wrote in message news:ev**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have a Repeater with a DataReader.
I can successfully let the code run with something like this
<asp:label id="testlabel" text='<%# DataBinder.Eval(Container.DataItem,
"Name") %>' runat="server"></asp:label>

but now I would like to code this few line ItemTemplate in my code-behind
page, how do I do it ?


Thanks,
Tee

Nov 18 '05 #2

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

Similar topics

3
2692
by: Tommy | last post by:
I have been working on getting nested repeaters to work for several days. When I add a repeater inside my item template i cannot see it in my code and can't set the datasource for it, etc, thus...
2
1778
by: News | last post by:
Hi I need help to display and edit data in a data grid within a repeater. The code is below: Sub dgrdEvents_EditCommand(sender As Object, e As DataGridCommandEventArgs)...
3
1351
by: Tommy | last post by:
I have been working on getting nested repeaters to work for several days. When I add a repeater inside my item template i cannot see it in my code and can't set the datasource for it, etc, thus...
2
1901
by: GD | last post by:
I'd like to use a Repeater to display data coming back from a cross-tab report. Because it's a cross-tab, I generally don't know how many columns are coming back. They do follow a certain format: ...
3
256
by: Tommy | last post by:
I have been working on getting nested repeaters to work for several days. When I add a repeater inside my item template i cannot see it in my code and can't set the datasource for it, etc, thus...
0
7196
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...
1
6878
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
5456
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,...
0
4583
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...
0
3088
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
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...

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.