0

I'm creating a column through ItemTemplate in my gridview, how can i adjust it to be my last column, unfortunately .net is making this column to be the first in grid view i want it to be the last column. The rest of the columns are automatically created by this code.

I mean

gridview1.datasource = myArrayList
gridview1.databind()

Please help me

Thanks in anticipation

1 Answer 1

1

Don't use the auto generation feature (AutoGenerateColumns="false") and supply the columns in the <columns> collection of the grid, or use LINQ:

var list = new List<MyClass>
{
   new MyClass { Name = "A", Value = 1, Key = 1 }
};

gridView1.datasource = list.Select(i => new
{
    i.Key,
    i.Name,
    i.Value
});

THe first option will be better on performance.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, I'm not using Linq for my project. And I get the arraylist from the session in this manner. ArrayList selectedComponentsForDownload = (ArrayList)Session["SelectedRowItems"]; SoftwareDownloadsGridView.DataSource = selectedComponentsForDownload; SoftwareDownloadsGridView.DataBind(); And i want to add additional column at the end of created gridview using the item template but it always creates the column as first. How do i force it to be the last column ? Thank you in anticipation
@user653622 - You don't require linq, brain was just giving an example. In your case, mark AutoGenerateColumns = "false" in gridview properties. Then go to the Columns Property of GridView and refresh the schema if you have attached Datasource on the designer or else, add columns manually and populate the DataField property of the particular column with whatever field you want.
Yes explicitly define the columns. Easiest, most performant way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.