How to skip some items of a repeater

J

Julien Sobrier

Hello,
I would like to skip the display of some items of a repeater. I think I
need to do something like this:
<asp:Repeater ...>
<ItemTemplate>
<% if (a == b) { %>
...
<% } %>
</ItemTemplate>
</asp:Repeater>

But I can't find out the exact syntax, or if there is a better way to do
that.

Thank you
Julien
 
R

Rob MacFadyen

Julien,

In the ItemDataBound event of the repeator you could mark the item as not
being visible:

protected void Repeater1_ItemDataBound(
object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
string A = (string)((DataRowView)e.Item.DataItem).Row["A"];
string B = (string)((DataRowView)e.Item.DataItem).Row["B"];

if (A == B)
{
e.Item.Visible = false;
}
}
}


Would that work for you?

Regards,

Rob
 
J

Julien Sobrier

Thank you.

In my case, I have HTML and C# code inside the item::

<ItemTemplate>
<p><%# Convert.ToString( DataBinder.Eval(Container.DataItem, "xxxxxx")) %>
<asp:DropDownList ID="ListValues" runat="server" Visible="false">
</asp:DropDownList>
<asp:TextBox ID="FreeText" runat="server" Visible="false">
</asp:TextBox><br />
<span style="font-style:italic"><%# Convert.ToString(
DataBinder.Eval(Container.DataItem, "yyyy")) %></span></p>
</ItemTemplate>

Julien

Rob said:
Julien,

In the ItemDataBound event of the repeator you could mark the item as not
being visible:

protected void Repeater1_ItemDataBound(
object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
string A = (string)((DataRowView)e.Item.DataItem).Row["A"];
string B = (string)((DataRowView)e.Item.DataItem).Row["B"];

if (A == B)
{
e.Item.Visible = false;
}
}
}


Would that work for you?

Regards,

Rob

Julien Sobrier said:
Hello,
I would like to skip the display of some items of a repeater. I think I
need to do something like this:
<asp:Repeater ...>
<ItemTemplate>
<% if (a == b) { %>
...
<% } %>
</ItemTemplate>
</asp:Repeater>

But I can't find out the exact syntax, or if there is a better way to do
that.

Thank you
Julien
 
T

Tim_Mac

hi Julien,
you could always iterate over each row of the datasource before
data-binding, and remove the rows directly. i can't imagine this would be
any slower than alternative approaches.

good luck
tim
 

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
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top