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. dynamically assign tag properties

dynamically assign tag properties

Scheduled Pinned Locked Moved ASP.NET
csharpquestionannouncement
4 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.
  • J Offline
    J Offline
    jpribele
    wrote on last edited by
    #1

    here is a simplified version of the page i have <% for( int i =0; i < 10; i++ ) { %> <% }%> this doesn't assign the value of i the commandargument is assigns <%=i%> i also tried CommandArgument='<%i%>' assigns <%i%> CommandArgument='<%#i%>' doesn't compile can't find i is this possible in .net ?

    I 1 Reply Last reply
    0
    • J jpribele

      here is a simplified version of the page i have <% for( int i =0; i < 10; i++ ) { %> <% }%> this doesn't assign the value of i the commandargument is assigns <%=i%> i also tried CommandArgument='<%i%>' assigns <%i%> CommandArgument='<%#i%>' doesn't compile can't find i is this possible in .net ?

      I Offline
      I Offline
      Ian Darling
      wrote on last edited by
      #2

      You should be using the databinding approach <%# %> - I think the reason it can't find 'i' is because the variable is out of scope at that point (databinding calls are standalone, and only know about the class. Try either: Calling a protected level property in the code-behind which returns the value instead, and use that in the for loop Or: Using a repeater control, databinding to an array/datatable/whatever with the values in, and using Databinder.Eval to get the value. -- Ian Darling If I was any more loopy, I'd be infinite.

      J 1 Reply Last reply
      0
      • I Ian Darling

        You should be using the databinding approach <%# %> - I think the reason it can't find 'i' is because the variable is out of scope at that point (databinding calls are standalone, and only know about the class. Try either: Calling a protected level property in the code-behind which returns the value instead, and use that in the for loop Or: Using a repeater control, databinding to an array/datatable/whatever with the values in, and using Databinder.Eval to get the value. -- Ian Darling If I was any more loopy, I'd be infinite.

        J Offline
        J Offline
        jpribele
        wrote on last edited by
        #3

        i figured that is what somebody was going to say. I can't really do databinding. what I have to display is to complicated and dynamic that is doesn't fit the very simply repeater pattern. thanks anyways

        K 1 Reply Last reply
        0
        • J jpribele

          i figured that is what somebody was going to say. I can't really do databinding. what I have to display is to complicated and dynamic that is doesn't fit the very simply repeater pattern. thanks anyways

          K Offline
          K Offline
          Knappen
          wrote on last edited by
          #4

          What I would have done is to build the list of buttons in the Page_Load method. And have a PlaceHolder tag in the HTML-part (aspx-page). The Placeholder component is god as it dosn't leav any html-tags.. Then I can do whatever complicated task in the code-behind. code-behind example: protected Placeholder plcButtons private void Page_Load(object sender, System.EventArgs e) { Button btn; for(int i=0;i<10;i++) { btn = new Button(); btn.Text="go" btn.OnCommand="GO" btn.CommandArgument= i plcButtons.controls.add(btn); } }

          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