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

  • Home
  • SEARCH
  • 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 7850453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:51:31+00:00 2026-06-02T18:51:31+00:00

I need to create buttons for each item in a DataList, but the last

  • 0

I need to create buttons for each item in a DataList, but the last button needs to be formatted differently, so it needs a different css class applied to it.

I think this should be done in the OntemDataBound method, but feel free to correct me if I’m wrong.

I want to do something like this:

protected void dlDataList_ItemDataBound(object sender, DataListItemEventArgs e)
{
  if (e.Item.ItemIndex == dlDataList.Items.Count - 1) //This doesn't work like I'd hoped
  {
    Panel button = (Panel)e.Item.FindControl("btnButton");
    button.CssClass = ("altClass");
  }
  ...
}

The problem is, I don’t think the datalist knows how many items it will have in the ItemDataBound event because dlDataList.Items.Count is always the same as the ItemIndex.

Any ideas on how I can give the last button the altClass css class?

  • 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-06-02T18:51:32+00:00Added an answer on June 2, 2026 at 6:51 pm

    Before you bind the DataList, save the total number of items in a page level variable. Then on your ItemDataBound, check to see if the current index is equal to the total items (-1 of course) and set your css class accordingly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a 'Reply' button that shows a form for any item
I need to create a menu component in which each menu item looks like
I need to create Encrypted PayNow paypal buttons on the fly for a website.
I need to create my own toolbar with set of buttons in the Visio
I need to create a row in XAML which has a label,two radio buttons..
I need to create button programatically with an image for normal and highlighted state
I have a PartialView which I need to create a button on, and once
I want to create custom button and I need it to be circle. How
I need to create a color animation. I have a control (a slick button
I have a view that will create a table while enumerating over each item

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.