www.webdeveloper.com
Results 1 to 5 of 5

Thread: How to change id values on a control while looping through.

  1. #1
    Join Date
    Jul 2004
    Posts
    61

    How to change id values on a control while looping through.

    I'm trying to add a hot news section with the TOP 3 results from the database into rounded edged tables. What I want to do is change the id value so it is not the same for each one. What I tried to do is add an incremented integer value at the end of "RoundedCorners1" with n being the incremented integer value and the tags looked like this:

    <% Response.Write("id=RoundedCorners1" & n) %>

    The problem is, I get an error saying that I cannot do this within a control. How would I go about changing the id value each time I loop through?


    Here's the code
    <skm:roundedcorners id="RoundedCorners1" runat="server" BackgroundBackColor="white"
    BackColor="#FFE0C0" BorderColor="Black" BorderStyle="Solid"
    BorderWidth="2px" Font-Names="Verdana"
    ImageDirectory="/Images/" Font-Size="12px"
    Width="150px" Padding="1px" CornerHeight="16px" TextHorizontalAlign="Center">

    This is a simple example with text in the rounded corners box. It has a width
    explicitly set to 150 pixels, and the images are anti-aliased.

    </skm:roundedcorners>

  2. #2
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    You don't need to do all of that. Just when you are looping it write the contents out in a div with a different class each time, like class1, class2, and then style that class differently with css. Let the browser read the css. You do not need to change any ids.

  3. #3
    Join Date
    Jul 2004
    Posts
    61
    If it's possible, could you give me an example of what it might look like? What I increment the CSS div each time or set it statically?

  4. #4
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    When you write it out, with a repeater or loop or whatever, you just swap out the value of the class, like you write out the variable and that would be a number 1 or 2 or something, then you have a class 1 or 2, and it gets the data from that. But you really do not have to change anything in the data base, you just change the value when the result is written out. If you use a repeater you can even use alternating item template etc so every other item gets a different template. Repeaters are by far the most efficient / stream lined way to write out data while giving the developer a ton of design control.

  5. #5
    Join Date
    Jul 2004
    Posts
    61
    I was able to use a repeater to do it and it worked. I'm new to repeaters that is why I didn't use them in the first place. Thanks for your help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles