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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:51:53+00:00 2026-05-21T02:51:53+00:00

I am trying to populate the values of multiple rows in single row in

  • 0

I am trying to populate the values of multiple rows in single row in gridview using c sharp in rowdatabound section of code behind page like:

Col1      Col6

a            1
a            2
a            3
a            4

I have changed this to

Col1     Col6

a           1 
            2
            3
            4

Now I want to achieve this, any help please?

Col1     Col6

a            1  2  3  4

What wrong with the code below?

if (e.Row.Cells[0].Text == "" && e.Row.Cells[5].Text != "")
{
    for (int a = 0; a<GridView1.Rows.Count; a++)
    {
        string s = GridView1.Rows[a].Cells[5].Text;
        GridView1.Rows[e.Row.RowIndex - 1].Cells[5].Text +=  s;
    }
}

What mistake I am making, anyone?

Cell[0]  is Col1
Cell[5]  is Col6
  • 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-21T02:51:53+00:00Added an answer on May 21, 2026 at 2:51 am

    I think you are approaching this from the wrong direction. Think of the GridView as your display only. You need to arrange the data as best you can before handing it off to the GridView. I am not sure how your data is stored but you might want to iterate through your data and create new records that essentially are a grouping and put all the data you need in a single row that you can databind to.

    The problem with using RowDataBound (or any databinding methods) is that you are dealing with data on a row by row basis which is not what you want since you can’t ‘see’ the other rows data in it’s context.

    As for arranging the data, you could use the following snippet to get you the comma seperated list of for each col1 value:

     string commaValues = string.Join(",",
         (yourList.Where(i => i.Col1.Equals(someValue)).
          Select(s => s.YourStringValue)).ToArray()));
    

    This will produce a comma delimited string for a given value (someValue in example):

     commaValues = "1,2,3,4,5"
    

    Use the above to make up a List of objects arranged so you can just bind to it directly. Eg:

    class NewObject
    {
        public string ID { get; set; }
        public string Text { get; set; }
    }
    
    List<NewObject> arrangedData = new List<NewObject>();
    // arrange the data here
    yourGrid.DataSource = arrangedData;
    yourGrid.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying populate H3 with the sum of column E for rows that
I'm trying to populate a dictionary dynamically in a for loop like so: pseudo-code
I'm trying to populate a DropDownList with values pulled from a property, and my
I'm trying to populate new HTML5 input attribute values into a Razor partial view.
I am trying to populate a text box based on the values from a
I'm trying to populate a mx:tree component with values that I'm getting from BlazeDS.
I'm trying to populate a select element with firstname and lastname values from a
I just started learning php last week and I am trying to populate values
I am trying to populate Select using knockout data-bind option for a list of
i'm using the source code for multiple selection Dropdown check-list Since, the example has

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.