Search code examples
c#repeaterindexoffindcontrolitems

How to find a control in a repeater with IndexOf C#


I want to know if it's possible to find a control in a repeater but by approximation. I mean, I have some controls with end "....EditMode" and I want to catch them all and modify some attribute

Something like this

foreach(RepeaterItem item in repeater1.Items)
{
     HtmlGenericControl divEditMode = item.FindControl("....IndexOf ("EditMode")");
     if(divEditMode != null)
     {
          divEditMode.Visible = false;
     }
}

Solution

  • foreach(RepeaterItem item in repeater1.Items)
    {
      foreach (var control in item.Controls)
      {
         if(control.ID.EndsWith("EditMode"))
         {
              control.Visible = false;
         }
      }
    }
    

    If I understand your wishes.