F
Fao, Sean
I'm trying to edit the data as it is being bound in an ASP.NET 1.1
Repeater, but I'm having no luck.
The relevant portion of my template is pasted below:
<tr>
<td colspan="4">
<asp:Label id="CommentsLabel" runat="server">
<%# DataBinder.Eval(Container.DataItem, "Comments") %>
</asp:Label></td>
</tr>
Basically, if the length of the "Comments" column is longer than
MaxCommentsLength, I'd like to chop off the end and attach "..." at the
end of the string. I attempted this with success using a DataGrid by
editing the string in the ItemDataBound event handler. However, I
noticed that with the Repeater control, the Data is not yet bound when
the ItemDataBound event is fired, so I have no way to determine what the
original value is so that I can modify it (at least not in the event
handler for the ItemDataBound event).
I tried the following code:
private void SoftDeletedCWMRepeater_ItemCreated(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
Label lbl;
int MaxCommentsLength = 15; // To be moved to web.config
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
if ((lbl = (Label) e.Item.FindControl("CommentsLabel")) != null)
{
if (lbl.Text.Length > MaxCommentsLength)
lbl.Text = lbl.Text.Substring(0, MaxCommentsLength) + "...";
} // end if
} // end if
} // end event handler
Using a debugger, I determined that the "Text" property of (Label)
e.Item.FindControl("CommentsLabel") was not yet set in the ItemCreated
event handler, which makes this code not work.
What are my options?
Thank you in advance,
Repeater, but I'm having no luck.
The relevant portion of my template is pasted below:
<tr>
<td colspan="4">
<asp:Label id="CommentsLabel" runat="server">
<%# DataBinder.Eval(Container.DataItem, "Comments") %>
</asp:Label></td>
</tr>
Basically, if the length of the "Comments" column is longer than
MaxCommentsLength, I'd like to chop off the end and attach "..." at the
end of the string. I attempted this with success using a DataGrid by
editing the string in the ItemDataBound event handler. However, I
noticed that with the Repeater control, the Data is not yet bound when
the ItemDataBound event is fired, so I have no way to determine what the
original value is so that I can modify it (at least not in the event
handler for the ItemDataBound event).
I tried the following code:
private void SoftDeletedCWMRepeater_ItemCreated(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
Label lbl;
int MaxCommentsLength = 15; // To be moved to web.config
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
if ((lbl = (Label) e.Item.FindControl("CommentsLabel")) != null)
{
if (lbl.Text.Length > MaxCommentsLength)
lbl.Text = lbl.Text.Substring(0, MaxCommentsLength) + "...";
} // end if
} // end if
} // end event handler
Using a debugger, I determined that the "Text" property of (Label)
e.Item.FindControl("CommentsLabel") was not yet set in the ItemCreated
event handler, which makes this code not work.
What are my options?
Thank you in advance,