Is there a way to display a bold gridline every third row in an ASP.NET GridView?

I am looking to create a grid layout with 3 rows, followed by a bold line to separate the 3rd row from the 4th row. Then I want another 3 rows, with another bold line separating the 6th row from the 7th row, and so on.

Any suggestions on how to achieve this layout?

For example:

Row 1
Row 2
Row 3
-------------
Row 4
Row 5
Row 6
-------------

Answer №1

This method should do the job just fine.

Behind-the-scenes code:

private int RowCounter { get; set; }

protected void myTable_RowDataBound(object sender, GridViewRowEventArgs e)
{
    switch(e.Row.RowType)
    {
        case DataControLRowType.Header:
            {
                RowCounter = 0;
            }
            break;
        case DataControlRowType.DataRow:
            {
                RowCounter += 1;
                if (RowCounter == 3)
                {
                    e.Row.CssClass = "LineBorder";
                    RowCounter = 0;
                }
            }
            break;
    }
}

Cascading Style Sheets:

tr.LineBorder td { border-bottom: 3px solid #000000; }

Answer №2

After studying chprpipr's response, I have devised a more concise approach that employs modulo and e.Row.RowIndex :

if (e.Row.RowType = DataControlRowType.DataRow)
{
    if ((e.Row.RowIndex + 1) % 3 == 0)
    {
        e.Row.CssClass = "BorderRow";
    }
}

If you substitute '% 3' with '% 5', for instance, the BorderRow CSS class will be applied every 5 rows instead of 3.

Answer №3

Check out this jQuery demonstration:

$(document).ready(function() {
    $("table.HighlightRows tr:nth-child(4)").addClass("BorderRow");
});

Whether it's a

<table class="HighlightRows">
or an
<asp:GridView CssClass="HighlightRows" />
, this script will function, assuming the CSS style is implemented as described in my previous .NET resolution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjust the alignment of the text to match the orientation of the image

When creating a layout with text and an image, I want them to be contained within a parent element that has a specified height, such as 100px. The text should adjust to the content, whether it's a short phrase or a lengthy paragraph, without a fixed ...

I need help figuring out how to get a horizontal scrollbar positioned at the top of a div to function properly once the content has been loaded using ajax

HTML CODE <div id="scrollidout" style="overflow: auto; overflow-y: hidden; "> <div id="scrollidin" style="padding-top: 1px; height: 20px; width: 1000px">&nbsp;</div> </div> <div class="resultcontent" style="overflow ...

What is the best way to populate a gridview with database values using C#?

selectdata.cs public List<BranchMaster> RetrieveBranchData() { List<BranchMaster> BranchmasterList = new List<BranchMaster>(); try { Database db = new SqlDatabase(connectionstring); ...

Styling Dropdown Menu Options

Is there a way to format two strings in a select list and display them as shown below? The first string should begin with 'Item1' followed by spaces until 10 spaces are taken up, then add a delimiter '|' and the second string. So all ...

Create a notification menu in Bootstrap using Bootply, which conveniently displays a numerical badge at the top

I am interested in implementing a bootstrap notification menu similar to the one found at this link: http://www.bootply.com/oasBuRC8Kz# However, I would like to add the number of notifications to the upper right corner of the glyphicon. I have gone throug ...

Tips for choosing only certain CSS selector declarations

Although I am primarily a PHP developer, I recently encountered an issue while developing a Joomla component. When installing my component on different Joomla websites, it also inherits the CSS styles of the parent template, which is causing some unwanted ...

The dropdown menu displaces nearby content

Visit this website for more information To access the blog section, simply click on "BLOG" in the top menu. Once there, look to the right side under the circle logo and select "Dísznövények" from the dropdown menu. Be cautious of long content strings b ...

Achieving 100% height in a div container using flex while maintaining vertical centering

Struggling to center text and buttons using flexbox while keeping the columns equal? Setting column height as 100% can be a challenge. If you set the height to 100%, vertical alignment may no longer be centered. Avoid resorting to tables or JavaScript for ...

Trouble with z-index functionality in jQuery datatable

I'm struggling to get the Action Box displayed as an upper layer. I've already tried using z-index but it doesn't seem to make any difference. https://i.stack.imgur.com/rJ1vL.png $(document).ready(function () { ...

Determining the current state of a CSS3 animation with jQuery

For example, I have this code snippet: @-webkit-keyframes anim { 0% { -webkit-transform: translate(-100px,0px) rotate(5deg); } 50% { -webkit-transform: translate(-140px,-5px) rotate(10deg); } 100% { -webki ...

Convert HTML content to a PDF file with Java

Welcome to the community! My project involves extracting data from a website containing information on various chemical substances and converting it into a PDF while preserving the original HTML formatting, including CSS styles. For example, here is a li ...

IE7 encountering a mixed content error when using html5shiv and SSL

In the process of developing my ASP.Net application that utilizes html5shiv and SSL, I encountered mixed content errors in IE7 specifically when using html5shiv. Interestingly, removing html5shiv eliminated the errors. Additionally, my app incorporates upd ...

Leveraging Server.Transfer in N2CMS for contentItem page management

Can the Server.Transfer() method be used to switch content between 2 different pages that are both ContentItem Pages? I am attempting to replace the content of one page with another, but when using the Transfer() method, an exception is thrown because th ...

Switch between multiple unordered lists (ul) so that when one list is clicked, the other lists reset to their initial state as though they were never

When I click on the first item in the ul list, it should slideToggle() to show its corresponding items. Similarly, when I click on the second item in the ul list, its items should slideToggle(), but the first ul list remains visible as well. What I am tryi ...

tips for displaying a label and text side by side on a single line

Is there a way to keep my label and text on the same line by adjusting the CSS? I've tried using float based on suggestions from other posts, but they still end up on different lines. .indentColumn { width: 71px; padding-top: 5%; } .labelColumn ...

jQuery and CSS3 for importing and customizing text files

I successfully customized the file input utilizing jQuery and CSS3. However, there is one aspect I couldn't quite figure out. After the user selects an image or file, I want to display the selected file's text at the very bottom of the text like ...

A Guide to Overflowing Text Above Divs - Even When the Parent Div has a Width of 0%

My webpage, built with Bootstrap 4, features a row with three divs placed horizontally. The divs have different percentage widths and sometimes the center div's width is set to 0%. However, I need to ensure that the text within the 0% div is always v ...

The text consistently remains positioned to the right of my image

Photo Gallery Title Issue I'm working on a photo gallery project where I want to add titles underneath each image. However, I'm facing a problem where the title is appearing next to the image instead of below it. You can see the issue in this sc ...

How to use CSS absolute positioning for a div with dynamic height to automatically adjust the container size

I have scoured the internet in search of posts discussing a similar issue to mine, but unfortunately I have not been able to find a solution that brings me closer to resolving it. As it stands, I am facing a challenge with a DIV setup. I have a Container ...

What is the best way to eliminate items from the query string before redirection?

Is there a way to remove an item from the query string and redirect without directly modifying Request.QueryString because it is read-only? I am looking for a solution that doesn't involve iterating through the collection. ...