Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3279464
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:35:44+00:00 2026-05-17T19:35:44+00:00

CSS & html id0 is the class for the div that’s got background as

  • 0

CSS & html

id0 is the class for the div that’s got background as a sprite image and inside of this div..there’s a list of links (in repeater)..when the user hovers over links..the background image of div displays diff parts of sprite image accordingly

Now I want that the classes id1 to id5 be set as the classes of the repeater’s list…now how do I go abut it?

like the list of links inside of repeater is coming from the DB..how do I create div tags inside of this repeater

and how do I set the class for each of the 5 divs that will be created and set these classes on them ?

like earlier I had simple markup but now I have to generate that list of links using a repeater..so how do I apply the CSS now ??

Please give some ideas..thnx

[EDIT]
ok tried this..
added div tag in repeater after label and in code behind :-
rpt1.FindControl(“myDiv”).Controls.Add(class= ??) //what to type here
use for loop or what ?

[edit] this doesnt work..whats wrong ?**

for(int i=1;i<6;i++)
                {
            rpt1.FindControl("myDiv").Controls.Add("class=id[i]");

            }

The above’s giving the following error:-

The best overloaded method match for ‘System.Web.UI.ControlCollection.Add(System.Web.UI.Control)’ has some invalid arguments

Now how do I set classes for the divs?

pch..made dilly mistake..made changes ..

 for (int i = 1; i < 6; i++)
                    {
                        string divClass = "id";
                        rpt1.FindControl("myDiv").Controls.Add("class=id" + i);

                    }

still the same error..

[edit]

tried the following..doesnt work

rpt1.FindControl("myDiv").Attributes.Add("class","id" +i);

[edit]

I tried the following now..

rpt1.FindControl("myDiv").Attributes["class"] = "id" + i;

it says “Cannot apply indexing with [] to an expression of type ‘method group'” ???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:35:45+00:00Added an answer on May 17, 2026 at 7:35 pm

    The ItemDataBinding way

    In order to get hold of an element inside the repeater’s ItemTemplate you have to declare it runat=”Server” and set an id for it (id isn’t really neccessary, but simplifies things). If you do that with your div you can get it inside your ItemDataBound event and set the class.

    void Repeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
      if (e.Item.ItemType == ListItemType.Item
        || e.Item.ItemType == ListItemType.AlternatingItem)   
      {
        ((HtmlGenericControl)(e.Item.FindControl("myDiv"))).
           Attributes["class"] = "id" + index++;
      }
    }
    

    You need to declare the index variable and increment it as you set each class.


    Alternative way

    An even simpler and cleaner way IMHO is to set the class directly in the View using data binding

    <asp:Repeater ID="rpt" runat="server">
      <ItemTemplate><div class="<%# GetDivClass() %>">a div</div></ItemTemplate>
    </asp:Repeater>
    

    and in the code behind declare the method for getting the data

    private int index = 1;
    
    protected string GetDivClass()
    {
      return "div" + index++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.