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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:11:19+00:00 2026-05-11T19:11:19+00:00

I have a DataView that was already populated with data (Verified this to be

  • 0

I have a DataView that was already populated with data (Verified this to be true).

I then set the DataSource of my GridView to that DataView and called the .DataBind() Function.

Right after binding, I checked the column count of my GridView (grid.Columns.Count) and it shows 0. But it is showing the right output with 15 columns.

Also, accessing a column using its index will throw an exception.

How can I access the column then?

Thanks!

EDIT — Additional Info:

I actually need to add a “glyph” (UP/DOWN arrow) in the column header to show what column are being sorted and its direction. The code below is what I am using. Problem is, the Columns.Count is always zero.

    for (int i = 0; i < dgData.Columns.Count; i++)
    {
        string colExpr = dgData.Columns[i].SortExpression;
        if (colExpr != "" && colExpr == dgData.SortExpression)
            item.Cells[i].Controls.Add(glyph);
    }
  • 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-11T19:11:19+00:00Added an answer on May 11, 2026 at 7:11 pm

    Edit

    Try this, it’s a little fugly as it relies on testing the linkbutton text against the GridView SortExpression. The Gridview ID is “test”

        protected void test_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                foreach (TableCell tc in e.Row.Cells)
                {
                    if(test.SortExpression.Contains( (tc.Controls[0] as LinkButton).Text ))
                        tc.Controls.Add( glyph )
                }
            }
        }
    

    I don’t think the columns collection is set if you are auto generating the columns…

    You could check the Row.Cells.Count or if you need column names, grab the HeaderRow, and iterate through the Cells & grab their .Text Value.

    If the GridView is sortable (e.g. has clickable links in the header, then to get the column names you’ll need to check

    foreach(Row r in GridView.Rows)
    {
        if(r.RowType == HeaderRow)
        {
             r.Cells[0].Controls[0]; //Link Control is here.
        }
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add two DataViews together to have one Dataview that can then
I have a dataView where I am binding data to a table. This is
I currently have an asp.net page, that takes in the data from this view
I have data that gets displayed in gridview. If I'm pulling it from one
I have a dataview defined as: DataView dvPricing = historicalPricing.GetAuctionData().DefaultView; This is what I
Using dotnet 2.0. I currently have code like this : DataView dv = new
I have a dataview that contains a list of tables. I am reading in
I have a SP Dataview that I have converted to XSLT, so that I
i have a GridView bound to a DataView. Some columns in the DataView's table
If you have a DataGridView that is bound to a DataView (someDataTable.DefaultView). ..and a

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.