Yes, you can generate any datasource with any data or column field in it. The point is to let GridView know which field you need to show. Of course, you can set AutoGenerateColumns="true" in GridView to let GridView displays columns according to the datasource
automatically. Another way is you can create dynamic GridView columns manually, then you can set the bind field manually according to the datasource:
knbinoj
Member
7 Points
86 Posts
Customize gridview fields
Jun 19, 2012 02:16 PM|LINK
Hi all,
I have a search results grid.
Now the grid binds with a list of Model class.
A new requirement arrived ie. The user can select fields which he would like to display in the grid view.
A solution in my mind is that, generate an inline query to accommodate the custom fields and then use a datatable to bind grid.
Am I in the right direction? or do we have a solution with a list of model class itself?
Thanks in advance,
Binoj K N
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Customize gridview fields
Jun 21, 2012 07:01 AM|LINK
Hi,
Yes, you can generate any datasource with any data or column field in it. The point is to let GridView know which field you need to show. Of course, you can set AutoGenerateColumns="true" in GridView to let GridView displays columns according to the datasource automatically. Another way is you can create dynamic GridView columns manually, then you can set the bind field manually according to the datasource:
http://www.codedigest.com/Articles/ASPNET/168_Create_Dynamic_GridView_Control_in_C_ASPNet.aspx
http://aspalliance.com/1558_Dynamic_GridView_and_DataList_in_ASPNET_20.7
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework