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 7278353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:51:47+00:00 2026-05-28T22:51:47+00:00

I need to display data from a database in a html table. I am

  • 0

I need to display data from a database in a html table. I am currently using a ListView control.

I want the final HTML table to render something like the following, where some rows have a rowspan attribute greater than one. The reason for this is that some fields have several rows of information, but correspond to the same logical entry.

For example:

|---------|---------|----------|----------|
| data    | data    |data      | data     |
|         |         |----------|          |
|         |         |data      |          |
|         |         |----------|          |
|         |         |data      |          |
|---------|---------|----------|----------|
| data    | data    |data      | data     |
|         |         |----------|          |
|         |         |data      |          |
|         |         |----------|          |
|         |         |data      |          |
|---------|---------|----------|----------|
| data    | data    |data      | data     |
|         |         |----------|          |
|         |         |data      |          |
|         |         |----------|          |
|         |         |data      |          |
|         |         |----------|          |
|         |         |data      |          |
|         |         |----------|          |
|         |         |data      |          |
|---------|---------|----------|----------|

What is the easiest way to accomplish this in ASP.net?

  • 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-28T22:51:48+00:00Added an answer on May 28, 2026 at 10:51 pm

    Not too elegant solution for ListView. The main idea is to use Repeater inside the ListView and bind all the sub-data(I mean data from the third column in your example) except the first record to it.

    <asp:ListView runat="server" ID="lstData">
        <LayoutTemplate>
            <table>
                <asp:PlaceHolder runat="server" ID="itemPlaceholder" />
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td <%# GetRowspan((int)Eval("Data.Length")) %>>
                    <%# Eval("FirstName") %>
                </td>
                <td <%# GetRowspan((int)Eval("Data.Length")) %>>
                    <%# Eval("LastName") %>
                </td>
                <td>
                    <%# GetFirst((IEnumerable<string>)Eval("Data")) %>
                </td>
                <td <%# GetRowspan((int)Eval("Data.Length")) %>>
                    <%# Eval("Country") %>
                </td>
            </tr>
            <asp:Repeater runat="server" 
                DataSource=<%# GetRest((IEnumerable<string>)Eval("Data")) %>>
                <ItemTemplate>
                    <tr>
                        <td>
                            <%# Container.DataItem %>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </ItemTemplate>
    </asp:ListView>
    

    and code behind:

    public override void DataBind()
    {
        var item1 = new { FirstName = "John", LastName = "Doe", 
            Data = new[] { "first", "second", "third" }, Country = "US" };
        var item2 = new { FirstName = "Jane", LastName = "Doe", 
            Data = new string[] { }, Country = "CA" };
        var item3 = new { FirstName = "Joe", LastName = "Public", 
            Data = new[] { "first", "second", "third", "fourth" }, Country = "US" };
    
        lstData.DataSource = new[] { item1, item2, item3 };
        lstData.DataBind();
    }
    
    protected string GetRowspan(int length)
    {
        if (length == 0)
            return string.Empty;
        else
            return string.Format("rowspan='{0}'", length);
    }
    
    protected string GetFirst(IEnumerable<string> data)
    {
        return data.FirstOrDefault();
    }
    
    protected IEnumerable<string> GetRest(IEnumerable<string> data)
    {
        if (data.Any())
            return data.Skip(1);
        else
            return Enumerable.Empty<string>();
    }
    

    this outputs data in the format you want.

    But if the usage of ListView is not necessary you could take a look onto GridView. There is more elegant way to do this by using it – ASP.NET GridView RowSpan using RowCreated Event – How to add Table Dynamic RowSpan with GridView article.

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

Sidebar

Related Questions

I'm using the Repeater control on my site to display data from the database.
We have a situation where we need to display data from a database in
I need to display a real time data from MS SQL 2005. I saw
I have a DataTable of data from an Access database that I need to
I am retrieving data from a SQL table so I can display the result
how do i insert items into an html listbox from a database? im using
I am using Datatables + jEditable to display data from my db and allow
Basically I have a table that is being used to display data from an
What is the best way to display results and data coming from Database in
I have a page that display some data. It is loaded from a database

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.