Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. FindControl which is inside of a Repeater control

FindControl which is inside of a Repeater control

Scheduled Pinned Locked Moved ASP.NET
helpcssdatabasequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thilina madush
    wrote on last edited by
    #1

    linkButton lnkBtnRemove=(linkButton)Repeater1.items[0].findControl("lnkRemove");
    lnkBtnRemove.visible=false;

    i used above code to make visible false of a link button i have placed in a repeater control.but it gives me the below error message. "Index was out of range.Must be non-negative and less than the size of the collection.Parameter name:index" i'm trying to use this in Page_load .pls help??

    N N 2 Replies Last reply
    0
    • T Thilina madush

      linkButton lnkBtnRemove=(linkButton)Repeater1.items[0].findControl("lnkRemove");
      lnkBtnRemove.visible=false;

      i used above code to make visible false of a link button i have placed in a repeater control.but it gives me the below error message. "Index was out of range.Must be non-negative and less than the size of the collection.Parameter name:index" i'm trying to use this in Page_load .pls help??

      N Offline
      N Offline
      nainakarri
      wrote on last edited by
      #2

      Hi I tried the same piece of code and it worked for me. Make sure that you first bind the data to repeater control and then make it false. Naina

      Naina

      1 Reply Last reply
      0
      • T Thilina madush

        linkButton lnkBtnRemove=(linkButton)Repeater1.items[0].findControl("lnkRemove");
        lnkBtnRemove.visible=false;

        i used above code to make visible false of a link button i have placed in a repeater control.but it gives me the below error message. "Index was out of range.Must be non-negative and less than the size of the collection.Parameter name:index" i'm trying to use this in Page_load .pls help??

        N Offline
        N Offline
        Navin Pandit
        wrote on last edited by
        #3

        Hii, You are getting error bcz your it unable to find th row at 0th index. So better use in the Repeater1_ItemDataBound event, also must check the condition: protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == DataControlRowType.DataRow) { // your code.. LinkButton lnk = (LinkButton)e.Item.FindControl("control_id"); } } Or you can also go for this: This code will work inside/outside of anyevent foreach (RepeaterItemCollection item in Repeater1.Items) { LinkButton lnk = (LinkButton)item[0].FindControl("control_id"); } Now choice is yours which is more suitable for you but also mind in which scope you are using the code. Navin C.

        T 1 Reply Last reply
        0
        • N Navin Pandit

          Hii, You are getting error bcz your it unable to find th row at 0th index. So better use in the Repeater1_ItemDataBound event, also must check the condition: protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == DataControlRowType.DataRow) { // your code.. LinkButton lnk = (LinkButton)e.Item.FindControl("control_id"); } } Or you can also go for this: This code will work inside/outside of anyevent foreach (RepeaterItemCollection item in Repeater1.Items) { LinkButton lnk = (LinkButton)item[0].FindControl("control_id"); } Now choice is yours which is more suitable for you but also mind in which scope you are using the code. Navin C.

          T Offline
          T Offline
          Thilina madush
          wrote on last edited by
          #4

          thnks for the anzr.but didn't worked.it cant find any item index in the repeater control,i don't no why?help needed.. :( :( thnks in advance.

          N 1 Reply Last reply
          0
          • T Thilina madush

            thnks for the anzr.but didn't worked.it cant find any item index in the repeater control,i don't no why?help needed.. :( :( thnks in advance.

            N Offline
            N Offline
            Navin Pandit
            wrote on last edited by
            #5

            Hii, Use this or mail me your scenario in which scope you want to use. Remmeber, before using this lines of code, you must bind your repeater control, otherwise it will not work as the control has no values. Hope this will work: foreach (RepeaterItem item in Repeater1.Items) { Label lbl = (Label)item.FindControl("lblName"); // Use any othe asp control that you want instead of 'Label'. if (lbl != null) { lbl.Text="I cached you!"; } } Or, for "DataBound" event of repeater you can use as:- protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Label lbl = (Label)e.Item.FindControl("lblID"); if(lbl!=null) { // Do your code with found control; } } } Regards, Navin C. E-mail: navin2k6@gmail.com :)

            modified on Tuesday, December 15, 2009 5:25 AM

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups