Improve company productivity with a Business Account.Sign Up


ASP.NET Repeater Control & Array Index

Posted on 2009-05-19
Medium Priority
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 500 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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In the video, one can understand the process of resizing images in single or bulk. Kernel Bulk Image Resizer is an easy to use tool for resizing large number of images. One can add and resize multiple images with this tool in single go. The video sh…
Did you know PowerShell can save you time with SaaS platforms? Simply leverage RESTfulAPIs to build your own PowerShell modules. These will kill repetitive tickets and tabs, using the command Invoke-RestMethod. Tune into this webinar to learn how…

584 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