can't set text for label within datalist

  • Thread starter Thread starter Dude
  • Start date Start date
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";
 
Write
<asp:label id="Label1" runat="server" text=<%# DataBinder.Eval
(Container.DataItem, "description")%>></asp:label>
Assign value to the Text Property of the Label
 
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
 
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?
 
Back
Top