How to skip some items of a repeater

  • Thread starter Thread starter Julien Sobrier
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top