tags:

views:

34

answers:

2

I have a blank/unbound GridView control on my form and I am binding it in the code behind like this:

GridView1.DataSource = _dataSet
DataBind()

Running this code populates my GridView control with all the columns and data that _dataSet has. I want to display only some of the columns, change the column names, and rearrange some of these columns too (i want the last column from the actual sql database table to be displayed first in my GridView).

Can someone show me how do do this?

+3  A: 

Set the AutoGenerateColumns property of the GridView to false and manually create the columns. That would be the easiest way.

Another way is to also set AutoGenerateColums property to false but this time, append the colums to the columns property of the GridView. Use the .Clear and the Add methods provided

citronas
Could you please provide a code sample of your second solution? I don't know how to append columns to the Columns property since that property is read-only; unless I misunderstood you. Thanks.
+2  A: 

First of all, in your GridView markup, you can change the header text:

<asp:BoundField DataField="SOME_COLUMN" HeaderText="Comment" SortExpression="SOME_COLUMN" />

Be sure to set AutoGenerateColumns to false.

Second of all, you can filter using DataSource.FilterExpression = "col1 = 'this'", if your dataset is being populated by a SqlDataSource or similar.

clifgriffin