开发者

Binding multiple data types to a single column in Gridview

Can anyone tell me if what is detailed in this example is possible with GridView using TemplateColumns. http://www.codeproject.com/KB/webforms/CustomDataGridColumn.aspx

开发者_StackOverflow社区I need to dynamically generate a GridView that may need not have one datatype in a column. Say Column 1 could have Checkbox or TextBox control (based on a logic, of course)

I tried implementing ITemplate and adding custom controls in InstantiateIn(), but as far as I understand - the binding here on on a per column level and not on per Item level.

How can I acheive this?

Thanks in advance. I can stub out the code I have if the question needs more clarification.


Yes, Telerik's RadGrid supports this.

The same code will work with only minor changes. For example, ListItemType becomes GridItemType. DataGridItem becomes GridDataItem, etc. Also, the way Telerik creates the controls means some of the indices need to change. For example, their ItemDataBound event has this code:

  string dataType = e.Item.Cells[0].Text;

but with a Telerik RadGrid, that needs to be:

 string dataType = e.Item.Cells[2].Text;

Other than those kinds of minor changes, it all works with RadGrid.

Note: When I see code samples from Telerik, they generally go a different route. The way I've seen them provide custom content for a cell is to put your customization logic in the ItemCreated event. That will be called for each row. So you can have the column's template contain all the possible controls and then in ItemCreating event, modify the instance of that template by setting the correct control to Visible based on your logic (this is the approach used in the article you linked to). Or you could create only a single specific control in that event for the correct type of control. Here is the documentation for the ItemCreated event and also a code sample from Telerik that modifies a LinkButton for each row but the same approach can be used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜