Search code examples
c#asp.netgridviewcode-behindsqldatareader

How do I avoid duplication of columns in a Gridview when using code-behind to execute sql query?


I have a sql query that I execute in code behind that returns data several rows long and multiple columns wide. I have a GridView on my aspx page, where I mention only certain columns because I want to either change the display name of the column, or manipulate it to present it as a link using HyperLinkField. I am binding the SqlDataReader to the gridview in code-behind.

The problem is, I notice columns repeating on the actual page. How do I avoid this?

Thanks for looking.


Solution

  • Have you set AutoGenerateColumns="false" on the GridView?

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.autogeneratecolumns.aspx