ASP.NET Repeater Control & Array Index

Posted on 2009-05-19
Last Modified: 2012-05-07
I have a working repeater control filled by an array. I have added a delete button, but am unsure how to reference the array index in the Command Argument to pass to the delete command.

<asp:Repeater ID="gvRC" runat="server">
      <li><%#Container.DataItem %>&nbsp;<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/icon_delete.gif" CommandName="deleteStation"  CommandArgument=" "  /></li>

The repeater is filled with a simple array by:
gvRC.DataSource = aryRC

Question by:el_scotty
LVL 12

Accepted Solution

wht1986 earned 125 total points
ID: 24424011
The index of the item is already included in the RepeaterCommandEventArgs argument of the ItemCommand event.

My code behind example is included below.  e.Item.ItemIndex contains the index of the item clicked.
 private List<string> DataSource
            if (ViewState["DATASOURCE"] == null)
                this.DataSource = new List<string>(new string[] { "Hello", "World", "Good Bye", "Sanity" });
            return (List<string>)ViewState["DATASOURCE"];
            ViewState["DATASOURCE"] = value;
    protected void Page_Load(object sender, EventArgs e)
        if (!this.IsPostBack)
            this.Repeater1.DataSource = DataSource;
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        if (e.CommandName.Equals("deleteStation"))
            this.Repeater1.DataSource = DataSource;

Open in new window


Author Closing Comment

ID: 31583089
Perfect, Thank You. I figured it must be something simple like that.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question