.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

DataTable and it's Gridview - A Column Order Question

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :ASP.Net

Well, I've been developing with gridviews for quite some time now.  Just recently I came across a situation that has me stumped.  Here's how the gridview has been working for me.


1.      A stored procedure from the database is called (three parameters are passed (reporttype, name, location)

2.     The data is retrieved using the SqlDataAdapter to fill a Datatable


4.     Columns are created programmatically as it reads the DataTable results (headertext, datafield, and dataformatstring are set at runtime)

5.     The Gridview triggers the databind event - and voila it works.


My dilemma is this:  the stored procedure (that I haven't developed) returns a various set of columns and column order.  I have one report type that does the following:


ReportType 1:  column orders returned in the following order when running directly in SQL

            col B, col C, col D, col E, col A


when I run the report through my gridview, the column order is as follows:


View Complete Post

More Related Resource Links

Gridview column line wrap question


I have a ASP.NET gridview (embedded into a DIV) with several columns. For some columns line wraps are definied and for some not(with ItemStyle.Wrap = true/false). For all columns ItemStyle.Width is set to a specific value. Now I am wondering, that there is a line wrap in a column, where ItemStyle.Wrap = false. What could be the reason for that?

WPF: how to make a GridView only sort on one column as ascending order?


We use GridView inside the Listview. We need the grid view alwasy sort on one column ascending order and not allow to click column header to change it.

Is there a easy way to achieve it in Xaml?

If not possible, how to achieve it in code behind?



Tooltip for GridView Column Headers (ASP.Net)

I just wanted to add auto tooltips for my GridView headers. There are couple of ways but I don't want to use javascript and wanted to use simple 'title' attribute. It took couple of hours to get the working code supporting sortable columns. I thought it will be very useful for others. Here's the code and logic behind it.

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

Use a column as parameter for a sds in another column; gridview


Hola, I have a gridview which is bound to a sds which returns 7 columns and I added two columns from the GUI.  What I want is to fill up the 9th column with DDLs and these  DDLS will get their data from a different sds which is using a stored procedure with a single parameter.  I created the 9th row, used template field, made the sds for 9th row, the stored_procedure, threw a DDL in Item template and all  I need now is to pass a parameter in the first column to the sds in the 9th column.  I can code this but i'm getting tired of aspx.cs :) and would like to do it from the GUI.

Rendering data with HTML tags in the DD Gridview for a selected column


I am having trouble finding out where and how to HTML Encode a cell's data on the Dynamic Data (v4.0) gridview of List.aspx.  As a simple case, suppose I have formatted cell data that is A<br/>B in the DB.    Obviously, I want A stacked on B in the cell.

It seems gridView1.HtmlEncode = true has gone away.

So maybe I'll try to catch it on the RowDataBound event:

protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)

            if (e.Row.RowType == DataControlRowType.DataRow)
                // Html Encode the cells


but this event never fires?

Has anyone figured out how to properly render HTML tags data in the List.aspx's GridView1? 

If I figure this out, then I can add a MetaAttribute called something like [EncodeAsHtml(true)] and be on my way.  Thanks!

How To Access Datakeys In Javascript...and How To make gridview Column Visible true in javascript


How To Access Gridview's Datakeys In Javascript...and How To make gridview Column Visible true in javascript

Reply me..

Order by Nemeric column


Hi all,

Thank you for advance.

the Document Rank column is numeric and contain the values are 2,1,0,4,0,5,3,0,6

we need to get the document rank with the following orders

how can i do this?

sum of 7 column totals in footer of gridview

I have implemented column tolals in the footer of my gridview using the technicque described in this article http://aspalliance.com/782 .Now I would like to have a total of the 7 column totals that are displayed in the footer.  Can anyone tell me how to do this.  I would like to display this in a label or an addition row in the footer if that is possible.

SSIS Changing Column Order during Transformation

First let me say, I really can't believe this chain of events myself--and they are happening to me. I am upgrading several DTS packages to SSIS on what will be my new production server.  These packages create tables, export them to a flat file, and ftp them off to other locations. What is happening (on the SSIS side) is that the OLE DB Source is reordering some of the columns on its own (moving them to the end of the table/file.  Then when my pickup/load routines run, the data is out of place and they fail. Can anyone please explain what is happening here with the mapping.  I have evaluated the table and the columns are in the order that I expect.  When I preview the source table in the OLE DB Source Editor the columns are in the correct order/alignment, but when them in the OLE DB Source Editor --Columns section within BIDS the order is changed arbitrarily. I have been somewhat successful (2 out of 3) in being able to re-map the data, but this last table just doesn't want to change.  Thanks in advance for any help and/or information you can provide

GridView Question - Please Help Me...Should Be Simple...

Hello,I have what I think should be a simple GridView question but I can't find the answer.When I want to update a row in Gridview I click on the "Edit" link.  It takes me into the row of the GridView where I can edit the values.Here's how it looks:   CustomerID CompanyName Edit 001 IBM Microsoft Apple Google Edit 002 IBM Microsoft Apple Google Edit 003 IBM Microsoft Apple Google Edit 004 IBM Microsoft Apple Google When I click on "Edit" it looks like:   CustomerID CompanyName Edit 001 IBM Microsoft Apple Google Update Cancel IBM Microsoft Apple Google Edit 003 IBM Microsoft Apple Google Edit 004 IBM Microsoft Apple Google As you can see, I now have the ability to update the CustomerID.  I don't the user to be able to update the CustomerID, only the CompanyName via the DropDown.How can I change the GridView to ONLY allow me to update the CompanyName?ThanksJason   CustomerID CompanyName Edit 001 IBM Microsoft Apple Google Edit 002 IBM Microsoft Apple Google Edit 003 IBM Microsoft Apple Google Edit 004 IBM Microsoft Apple Google

What is the meaning of Ascending\descending sort order of a column within an index

When I add a new index I can also specify the "sort order" as ascending or descending. What does it mean? does it affect performance? does it mean that the binary search tree will be set in a certain way?

How do I change the order of column names in EditForm.aspx

I have an Announcements list to which I've added extra columns: Publish (date), De-Publish (date), and Category (choice).  When I go to EditForm.aspx, the columns display in this order: Title , Body, De-Publish , Category and Publish . I'd like to change the order of the columns on EditForm.aspx so that it is Title, Body, Category, Publish and De-Publish . Changing the All Items view doesn't do it. How might I change the order of columns that is shown to the user?

How do I INSERT when I don't know the column order

If I know the order that columns are in (FirstName, LastName, PetName), inserting into a table is easy: INSERT INTO MY_TABLE ("Charlie", "Brown", "Snoopy") But if I only know the column names and not their order, how do I insert?

How to set the width of column on GridView

How to set the specific the width of each column, the columns are created automaticly 

How to save and restore column order in WPF?

Hi, I am working on WPF 4 DataGrid, and I was just wondering if there is a way to save column order to xml at application shutdown and restore column order at application startup. I am thinking of to create a class with properties like header name, display index and visibility, but i don't know how to map this to datagrid columns.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend