can't set text for label within datalist

D

Dude

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"
onUpdateCommand="myListUpdateHandler"
onCancelCommand="myListCancelHandler"
onDeleteCommand="myListDeleteHandler"
DataKeyField="ID">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td><asp:ImageButton runat="server" commandname="edit"
ImageUrl="/stap/images/arrow.jpg"
ID="Imagebutton1"></asp:ImageButton></td>
<td colspan="2"><asp:label id="LabelGoals"
runat="server"></asp:label>
<asp:label id="Label1" runat="server"><%# DataBinder.Eval
(Container.DataItem, "description")%></asp:label></td></tr></table>
</ItemTemplate>
</asp:DataList>

Label lblLabel = ((Label) e.Item.FindControl("LabelGoals"));
Trace.Write ("Target Label: " + lblLabel.ClientID);
lblLabel.Text = "dude";
 
S

Sonali.NET[MVP]

Write
<asp:label id="Label1" runat="server" text=<%# DataBinder.Eval
(Container.DataItem, "description")%>></asp:label>
Assign value to the Text Property of the Label
 
S

Sonali.NET[MVP]

Ya Marina thanks for pointing
To the Poster
Where and which event are you writing the code
Label lblLabel = ((Label) e.Item.FindControl("LabelGoals"));
Trace.Write ("Target Label: " + lblLabel.ClientID);
lblLabel.Text = "dude";
That's not really necessary - I have done it the other way, and it works just fine.

However, I believe the poster was referring to the LabelGoals label, not Label1.
Write
<asp:label id="Label1" runat="server" text=<%# DataBinder.Eval
(Container.DataItem, "description")%>></asp:label>
Assign value to the Text Property of the Label
 
D

Dude

As included in the code, I need to set the text of the "LabelGoals"
label. Should I need to do it from the init section?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top