Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:

I want to bind not all but one part of columns of a DataSource to a GridView, but I do not know which function can be used?

For example, the following code is used to bind all columns of database "Departments" to GridView departmentsGrid.

departmentsGrid.DataSource = dataSet.Tables["Departments"].DefaultView;
departmentsGrid.DataBind();

Note that for the GridView, I have set "AutoGenerateColumns" as True.

Therefore, I have to select all the columns to bind. Perhaps, I can set "AutoGenerateColumns" as False and then bind the columns one by one?

Or is there any better solution?

Thank you!

Posted
Updated 25-Aug-09 10:27am
v3

You have to do it on RowDataBound Event of Gridview.
 
Share this answer
 
v2
It is always better to specify columns on the designer and AutoGenerateColumns false. So that if the selection to departments changes the page becomes intact.

[thumbs up]

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900