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. How can I get the correct row in Repeater from LinkButton click?

How can I get the correct row in Repeater from LinkButton click?

Scheduled Pinned Locked Moved ASP.NET
questionhelpregex
2 Posts 1 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.
  • D Offline
    D Offline
    DeepToot
    wrote on last edited by
    #1

    I have a page with a Repeater. The rows from the Repeater after setting its datasource is as follows: Row1: LinkButton | Column1 | Column2 - asp:Panel with HtmlTable and additional repeater Row2: LinkButton | Column1 | Column2 - asp:Panel with HtmlTable andadditional repeater The initial load of the data only shows the row with LinkButton, the Panel and HtmlTable is to show only when the LinkButton of that row is selected. If there are two rows, the first linkbutton is clicked, it shows the Panel and HtmlTable for that row - if row 2's panel and HtmlTable is showing it needs to collapse and hide and only show the selected rows data. Hope this makes sense so far. The problem I am having is that now matter what Linkbutton I click, I am only getting the first instance of the items in the repeater. Meaning, I click row 2 and can only seem to get the reference to row 1's Panel and HtmlTable. I guess my initial question would be what is the correct way to be able to get the right control based on what linkbutton is clicked? Here is my click event for the linkbutton - what this does is once clicked it just needs to show the Panel associated with that link button. The code below is how I am trying to get a reference to the controls for that row. I put a HiddenField in the repeater that will tell me in the code below if we are to Expand the Panel (visible) or Collapse the Panel (hide it). When I click the first LinkButton on Row 1 here is the ID I get back from my controls: LinkButton returns: ctl00_MainContent_tabContainer_tabSearchFilings_SD1_rptResults_ctl01_lnkButton HiddenField ctl00_MainContent_tabContainer_tabSearchFilings_SD1_rptResults_ctl01_hidrptCourtOrderResults The panel that is brought back when I do a FindControl (see code below) is this: Panel returns: ctl00_MainContent_tabContainer_tabSearchFilings_SD1_rptResults_ctl01_pnlExpand So we match, but this is the first row. Clicking the second rows LinkButton produces this result: LinkButton returns: ctl00_MainContent_tabContainer_tabSearchFilings_SD1_rptResults_ctl02_lnkButton <-- WE now have ct102! Panel returns: ctl00_MainContent_tabContainer_tabSearchFilings_SD1_rptResults_ctl01_hidrptCourtOrderResults<-- this is still row 1's reference so now that I cannot get the ct102's reference I can only show row 1's Panel, not row 2's... Any idea what I am missing? Hope this made sense, ask if it didn't. Here are two screenshots to help explain what I am talking about.

    D 1 Reply Last reply
    0
    • D DeepToot

      I have a page with a Repeater. The rows from the Repeater after setting its datasource is as follows: Row1: LinkButton | Column1 | Column2 - asp:Panel with HtmlTable and additional repeater Row2: LinkButton | Column1 | Column2 - asp:Panel with HtmlTable andadditional repeater The initial load of the data only shows the row with LinkButton, the Panel and HtmlTable is to show only when the LinkButton of that row is selected. If there are two rows, the first linkbutton is clicked, it shows the Panel and HtmlTable for that row - if row 2's panel and HtmlTable is showing it needs to collapse and hide and only show the selected rows data. Hope this makes sense so far. The problem I am having is that now matter what Linkbutton I click, I am only getting the first instance of the items in the repeater. Meaning, I click row 2 and can only seem to get the reference to row 1's Panel and HtmlTable. I guess my initial question would be what is the correct way to be able to get the right control based on what linkbutton is clicked? Here is my click event for the linkbutton - what this does is once clicked it just needs to show the Panel associated with that link button. The code below is how I am trying to get a reference to the controls for that row. I put a HiddenField in the repeater that will tell me in the code below if we are to Expand the Panel (visible) or Collapse the Panel (hide it). When I click the first LinkButton on Row 1 here is the ID I get back from my controls: LinkButton returns: ctl00_MainContent_tabContainer_tabSearchFilings_SD1_rptResults_ctl01_lnkButton HiddenField ctl00_MainContent_tabContainer_tabSearchFilings_SD1_rptResults_ctl01_hidrptCourtOrderResults The panel that is brought back when I do a FindControl (see code below) is this: Panel returns: ctl00_MainContent_tabContainer_tabSearchFilings_SD1_rptResults_ctl01_pnlExpand So we match, but this is the first row. Clicking the second rows LinkButton produces this result: LinkButton returns: ctl00_MainContent_tabContainer_tabSearchFilings_SD1_rptResults_ctl02_lnkButton <-- WE now have ct102! Panel returns: ctl00_MainContent_tabContainer_tabSearchFilings_SD1_rptResults_ctl01_hidrptCourtOrderResults<-- this is still row 1's reference so now that I cannot get the ct102's reference I can only show row 1's Panel, not row 2's... Any idea what I am missing? Hope this made sense, ask if it didn't. Here are two screenshots to help explain what I am talking about.

      D Offline
      D Offline
      DeepToot
      wrote on last edited by
      #2

      I found the answer to my problem. The problem was I was looking in 'rptResults.Items[0].FindControl("hidrptCourtOrderResults");' for my controls and I forgot I could iterate through Item Collection of the Repeater to get the controls. So I am doing this: foreach(RepeaterItem rptItem in rptResults.Items) { }

      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