Yanker Yanker -4 years ago 75
ASP.NET (C#) Question

How to create a horizontal repeater? And how to make a button be seen as an icon?

I am using a repeater control that shows data for some table. Each row in the repeater contains two columns: an icon (red/yellow/green circle) and an explanation.

I have to Goals, the first goal is to create the same repeater only now I need it to be horizontal. The second goal is that I need each icon (red/ green/ yellow circle) to be a button so that when I press on one of the icons, an event occurs (doesn't matter what, say Response.Write("Green is Pressed");

Can you help me?

Answer Source

To make it horizontal you can use the li list as inline, a css trick. The full code for that :

<head runat="server">
    <style type="text/css">
    #navlist li
        display: inline;
        list-style-type: none;
        padding-right: 20px;
    <form id="form1" runat="server">
    <div id="navcontainer">
    <ul id="navlist">
    <asp:Repeater ID="Repeater1" runat="server">
            <li>Some text and my id: <%# GetID(Container.DataItem) %></li>

and on code behind:

public partial class Dokimes_StackOverFlow_HorizontialRepeater : System.Web.UI.Page
    List<int> oMainIds = new List<int>();

    protected void Page_Load(object sender, EventArgs e)
        for (int i = 0; i < 10; i++)

        Repeater1.DataSource = oMainIds;

    public int GetID(object oItem)
        return (int)oItem;

and you have a render like:

Some text and my id: 0 Some text and my id: 1 Some text and my id: 2 Some text and my id: 3 Some text and my id: 4 Some text and my id: 5 Some text and my id: 6 Some text and my id: 7 Some text and my id: 8 Some text and my id: 9

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download