473,507 Members | 6,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to programmatically assign text to a label control within a datalist template?

I have a label control that I've embedded in a datalist template. I will be
binding data to that label.

I want to run a string formatting function on the database text before it is
injected into the datalist. When I try to do this, I get a "... [control]
does not exist in the current context.

I need to know how to target the control. If I were writing Flash
actionscript, it would be something like

_root.myDatalist.myLabelInsideMyDatalist.Text =
processedTextThatIAlreadyRanThroughMyFunction

Is this possible? Am I running into a page lifecycle thing, or?

Thanks for any help. Actual code follows. I'm trying to inject the formatted
variable text into lblCon_Body.

-KF
<asp:DataList runat="server" id="DataList1" DataKeyField="Con_ContentID"
DataSourceID="SqlDataSource1" Width="100%" HorizontalAlign="Left"
CellPadding="0" >

<ItemTemplate>

<asp:Label Text='<%# Eval("Con_Title") %>' runat="server"
id="Con_TitleLabel" Font-Bold="True" Font-Size="Medium" />

<br />

<asp:Label Text='<%# Eval("Con_BylineCredit") %>' runat="server"
id="Con_BylineCreditLabel" Font-Italic="True" Font-Size="X-Small"
style="font-size: small; line-height: 15pt; font-style: italic; font-family:
Arial, Verdana, Sans-serif" />

<br />

<br />

<asp:Label Text='<%# Eval("Con_Body")%>' runat="server" ID="lblCon_Body"
Font-Italic="False" Font-Size="X-Small" style="font-size: small;
line-height: 15pt; font-style: italic; font-family: Arial, Verdana,
Sans-serif" /><br />

<br />

</ItemTemplate>

</asp:DataList>
Jun 5 '06 #1
1 3867
Yes, you can do that, but you have to get a reference to that control first,
using FindControl(id) and casting it as a label.

Here's an example:

foreach(DataListItem item in MyDataList.Items){
((Label)item.FindControl("lblCon_Body")).Text =
processedTextThatIAlreadyRanThroughMyFunction;
}
"ke*****@nospam.nospam" wrote:
I have a label control that I've embedded in a datalist template. I will be
binding data to that label.

I want to run a string formatting function on the database text before it is
injected into the datalist. When I try to do this, I get a "... [control]
does not exist in the current context.

I need to know how to target the control. If I were writing Flash
actionscript, it would be something like

_root.myDatalist.myLabelInsideMyDatalist.Text =
processedTextThatIAlreadyRanThroughMyFunction

Is this possible? Am I running into a page lifecycle thing, or?

Thanks for any help. Actual code follows. I'm trying to inject the formatted
variable text into lblCon_Body.

-KF
<asp:DataList runat="server" id="DataList1" DataKeyField="Con_ContentID"
DataSourceID="SqlDataSource1" Width="100%" HorizontalAlign="Left"
CellPadding="0" >

<ItemTemplate>

<asp:Label Text='<%# Eval("Con_Title") %>' runat="server"
id="Con_TitleLabel" Font-Bold="True" Font-Size="Medium" />

<br />

<asp:Label Text='<%# Eval("Con_BylineCredit") %>' runat="server"
id="Con_BylineCreditLabel" Font-Italic="True" Font-Size="X-Small"
style="font-size: small; line-height: 15pt; font-style: italic; font-family:
Arial, Verdana, Sans-serif" />

<br />

<br />

<asp:Label Text='<%# Eval("Con_Body")%>' runat="server" ID="lblCon_Body"
Font-Italic="False" Font-Size="X-Small" style="font-size: small;
line-height: 15pt; font-style: italic; font-family: Arial, Verdana,
Sans-serif" /><br />

<br />

</ItemTemplate>

</asp:DataList>

Jun 5 '06 #2

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

Similar topics

3
5337
by: Dude | last post by:
Below is the code - it is finding the control, and there is no error, just not assigning the text to the label <asp:DataList id="dlGoals" runat="server" onEditCommand="myListEditHandler"...
3
2621
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
4
3590
by: MasterChief | last post by:
I have an insert template textbox that is bound to a field in SQL. Since it is the insert template it really doesn't have anything in it. How do I set the default text? Like for example if I have a...
3
1940
by: Paul | last post by:
I am using Visual Studio.net 2005 (and asp.net 2.0) Let's say that in a Web Project, I have created a (Dataset?) called SomeDataset.xsd. On it I have a TableAdapter called SomeTableTableAdapter...
4
2134
by: Sam Martin | last post by:
Hi, I have got a User Control that contains for the sake of argument, a single DataList control. eg. <asp:DataList id="DataListMain" runat="server" RepeatDirection="Horizontal"...
2
2597
by: Nathan Sokalski | last post by:
I am trying to create a FormView controls in which I access and modify the the controls in the PagerTemplate programmatically. However, I continue to recieve the following error: Object...
2
15043
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
4
2187
by: .Net Sports | last post by:
I need to dynamically assign a datalist attribute upon a helper function receiving data from a querystring. If a user picks a certain region, i need the datalist to display its back color, or any...
3
2577
by: Ken Fine | last post by:
I am using ASP.NET's CreateUserWizard control. I want to force the visitor to use a username and e-mail address that I am providing in programming, and I do not want the visitor to be able to edit...
0
7221
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,...
0
7109
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
7372
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
7029
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
7481
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...
0
5619
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,...
1
5039
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
411
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.