siri
siri

Reputation: 723

make a cell as template field in GridView

I have a grid view which is dynamically populated with data. and the no.of columns may be changed each time according to the query.. i want to make the first field to select the row of data(by making it template field). I cannot declare statically the columns as template fields because the column numbers are dynamic. can any one help how to proceed.

Upvotes: 1

Views: 446

Answers (2)

NakedBrunch
NakedBrunch

Reputation: 49413

It's a bit of work but the following article walks through all of the steps: How to create template columns dynamically in a grid view

There is no easy answer for what you're trying to do but the above link will help you if you are willing to put in the time and effort to get it done.

Upvotes: 1

VinayC
VinayC

Reputation: 49195

You need to create your own template builder - a class implementing ITemplate interface - use InstantiateIn to build your template by adding needed controls to the given template container. Add TemplateField column to the grid-view and use your class as ItemTemplate.

See this article where this is illustrated: http://www.mindfiresolutions.com/How-to-add-a-TemplateField-to-a-GridView-dynamically-841.php

Further, what you want to achieve might be possible by creating your custom DataControlField - for example, for selection column, I may use a class inherited from CheckBoxField (something like http://www.asp.net/data-access/tutorials/adding-a-gridview-column-of-checkboxes-cs)

Upvotes: 1

Related Questions