Setting the number of columns in a GridView?

How do I set the number of columns in a GridView

Page 1 of 1

2 Replies - 5824 Views - Last Post: 07 March 2009 - 09:48 AM Rate Topic: -----

#1 plnelson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 11-February 09

Setting the number of columns in a GridView?

Post icon  Posted 07 March 2009 - 08:52 AM

I have a GridView displaying contents of a SQL table. The code-behind uses SqlDataAdapter, DataTable, and DataSet classes.

I don't want to display every column in my table - I want to leave a couple off the Gridview display. How do I control how many columns the GridView displays?

Thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: Setting the number of columns in a GridView?

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Setting the number of columns in a GridView?

Posted 07 March 2009 - 09:45 AM

Set the visible property of each column to False, for those that you do not want to be visible.
Was This Post Helpful? 0
  • +
  • -

#3 plnelson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 11-February 09

Re: Setting the number of columns in a GridView?

Posted 07 March 2009 - 09:48 AM

View Postplnelson, on 7 Mar, 2009 - 07:52 AM, said:

I have a GridView displaying contents of a SQL table. The code-behind uses SqlDataAdapter, DataTable, and DataSet classes.

I don't want to display every column in my table - I want to leave a couple off the Gridview display. How do I control how many columns the GridView displays?

Thanks in advance


Nevermind - I figured it out. In Properties I set AutoGenerateColumns = false. Then in the markup I set my own columns -
	   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
		  <columns>
			<asp:boundfield datafield="ColorName" headertext="Color Name"/>
			<asp:boundfield datafield="Red" headertext="Red Header"/>
			<asp:boundfield datafield="Green" headertext="Green Header"/>
			<asp:boundfield datafield="Blue" headertext="Blue Header"/>
		  </columns>



. . . I just used a simpleminded example for the above, but you get the idea.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1