Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3357666
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:39:37+00:00 2026-05-18T02:39:37+00:00

There’s this repeater… <asp:Repeater ID=myRepeater OnItemCommand=rpt1_ItemCommand runat=server OnItemDataBound=rpt1_OnItemDataBound> <HeaderTemplate> <table width=99% border=0 cellpadding=0 cellspacing=0>

  • 0

There’s this repeater…

 <asp:Repeater ID="myRepeater" OnItemCommand="rpt1_ItemCommand" runat="server" OnItemDataBound="rpt1_OnItemDataBound">
     <HeaderTemplate>
         <table width="99%" border="0" cellpadding="0" cellspacing="0">
             <tr class="lgrey">
                <td>Default</td>
             </tr>
     </HeaderTemplate>
     <ItemTemplate>
         <table>
             <tr>
                <td>
                    <asp:LinkButton ID="lnk1" Text="Make Default" CommandName="SetDefault" runat="server" Visible="True" CommandArgument='<%#Eval("UserID") %>' CausesValidation="false"></asp:LinkButton>
                    <asp:Label ID="label1" Text="Yes" runat="server" Visible="False"></asp:Label>
                </td>
             </tr>
     </ItemTemplate>
     <FooterTemplate>
         </table>
     </FooterTemplate>
</asp:Repeater>

What I want is that when user clicks on any of the “lnk1” link button in the lsit that repeater renders,
the link should be replaced with the label “label1”..ie when the user clicks on “Make Default” link, it should be replaced
with “Yes” label

Now when I click 2 link buttons, both get their label “Yes” displayed where as I want only one link button to display Yes
ie the one which has been clciked and rest of the items should display “Make Default” link button only.

ie Only ONE item should be displaying “Yes” label…now how do I iterate through the repeater items to set only ONE item
as default and not multiple ??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:39:38+00:00Added an answer on May 18, 2026 at 2:39 am

    You can iterate the repeater items collection,

    protected void myRepeater_ItemCommand(object sender, RepeaterCommandEventArgs e)
    {
    
        int selectedIndex = e.Item.ItemIndex;
        foreach(RepeaterItem item in myRepeater.Items)
        {
            ((LinkButton)item.FindControl("lnk1")).Visible = (item.ItemIndex != selectedIndex);
            ((Label)item.FindControl("label1")).Visible = (item.ItemIndex == selectedIndex);
        }
    }
    

    The pros of this option are: 1. no second hit on the database.

    Or I would put my logic in the ItemDataBound event instead, store the clicked link button index in a member variable and call DataBind in the command event handler.

    private int selectedIndex = -1;
    //...
    protected void myRepeater_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            selectedIndex = e.Item.ItemIndex;
    
            myRepeater.DataSource = MyGetDataMethod();
            myRepeater.DataBind();        
    
        }
    

    In the ItemDataBound handler compare the current index with the stored index and if they match show the label.

    protected void myRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                if(e.Item.ItemIndex == selectedIndex)
                {
                   ((LinkButton)e.Item.FindControl("lnk1")).Visible = false;
                   ((Label)e.Item.FindControl("label1")).Visible = true;
                }
    
            }
        }
    

    The cons of this second option are: 1. A second hit on the database. 2. If the user clicks say row two, and some other user inserts a new address record, row 2 may now be something different when you re-bind. Also if you’re not using an order by that could change between database calls and your stored selectedIndex could be invalidated thatway too.

    So in conclusion I’d go with option one now I’ve thought it all the way through.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a column that exists in 2 tables. In table 1, this column
There's a sample ASP.NET project with this controller: using System; using System.Collections.Generic; using System.Web;
There are nice SO question and answers about this issue, but these options didn't
There are two table s : one is the master and one the detail
There is a table view with three sections. The last section may contain many
There is this strange situation I'm fighting on. I have 3 pages, les call
There have been multiple questions regarding this topic but I have never really settled
I know there's a lot of other questions out there that deal with this
There is a term for this that I just cannot think of, and I'm
There is previous little on the google on this subject other than people asking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.