Thursday, July 19, 2007

Assign object list to a GridView in asp.net 2.0

Simply follow the scenario below.

1. Drag a GridView control to the page.
2. Assign the Object list into the grid as below.
// c# - Bind data to the drop down
GridView1.DataSource = userList;
GridView1.DataBind();


3. Run the application. That's all.

If you need to show only few columns, do the following.
1. Go to GridView Properties.
2. Open the "columns" property.
3. Uncheck the check box "Auto-Generate fields".
4. Add any type of fields and set the "DataField" to a property in your object for the selected field. For example "UserName".

1 comment:

Venkat said...

I have one more object in UsersList. how can i bind that?