473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Repeater Woes

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,

--
Sean
Jan 11 '06 #1
4 1585
With stuff like this, I usually create a helper method where I pass in the
original value and pass out the modified value.

You may have to tweak this as I am not compiling it but the general idea
would be as follows:

IN-CODE:
public static TruncateContent(string content){
if(content.Length != 200){
// truncate and return the shortend value.
}

return content;
}

IN-ASPX:
<%# MyUtilityClass.TruncateContent( DataBinder.Eval(Container.DataItem,
"Comments") ) %>
"Fao, Sean" <en**********@yahoo.comI-WANT-NO-SPAM> wrote in message
news:eA**************@TK2MSFTNGP10.phx.gbl...
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,

--
Sean

Jan 11 '06 #2
<asp:Label id="CommentsLabel" runat="server" />

in ItemsDataBound you can get the data that is going to get bound, via
e.Item.DataItem

so you can do
Label lbl = (Label) e.Item.FindControl("CommentsLabel");
string comments= DataBinder.Eval(e.Item.DataItem, "Comments");
if (comments.Length > XXX)
{
lbl.Text = comments.Substring(0, MaxCommentsLength) + "...";
}
else
{
lbl.Text = comments;
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Fao, Sean" <en**********@yahoo.comI-WANT-NO-SPAM> wrote in message
news:eA**************@TK2MSFTNGP10.phx.gbl...
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,

--
Sean

Jan 11 '06 #3
Peter Rilling wrote:
With stuff like this, I usually create a helper method where I pass in the
original value and pass out the modified value.


That's a great idea! Thank you very much!

--
Sean
Jan 11 '06 #4
Karl Seguin [MVP] wrote:
<asp:Label id="CommentsLabel" runat="server" />

in ItemsDataBound you can get the data that is going to get bound, via
e.Item.DataItem


Interesting. I could have sworn that I had tried that.

Thank you very much for your response,

--
Sean
Jan 11 '06 #5

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

Similar topics

0
by: Ed Allan | last post by:
http://ejaconsulting.com/nestedrepeater/NestedRepeater.txt >-----Original Message----- >Doh! The HTML has all been rendered . . . > >Right click on this link and select 'Save target as ..' >to...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
0
by: Amir | last post by:
Hi every one This is the problem: I have a UserControl that contains a Repeater and a few LinkButton. The Repeater generate some linkButton. I use this control for implementing paging solution...
3
by: sorCrer | last post by:
Hi All, Posted after extensive searching! I have a nested repeater control as follows: (Simplified ;-)) <table> <asp:repeater id=parent onItemDataBound=createChild> <tr><td>Level...
8
by: I am Sam | last post by:
Hi everyone, This problem is making me old. I don't want to get any older. I have a multi-nested repeater control as follows: <asp:Repeater ID="clubRep1" Runat="server">...
2
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: ...
8
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
0
by: uncensored | last post by:
Hello everyone, I'm fairly new at .Net and I have a repeater inside a repeater problem. I will attach my code to this message but basically what I am able to tell when I run my page it tells me...
0
by: hardieca | last post by:
Hi, I have bound a repeater to an objectdatasource to display comments at the end of my blog. People may enter their email or omit it. When the repeater is rendering, I would like to evaluate...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.