开发者

Problem with dynamically added subheader into custom GridView

I'd like to get a grid with ability to add subheader (one or several rows) according to value of certain column (data source is grouped sorted by this column). Within my inherited GridView I override OnRowDataBind method: If value of considering column on current call of OnRowDataBind is not equal to previous values, then special header row is inserted before current row.

Table tbl = this.Controls[0] as Table; //this - pointer to CustomGridView tbl.Controls.AddAt(rowIndex + add_counter + 1, NewSubHeaderRow); /*rowIndex - RowIndex of cur开发者_StackOverflow社区rent row, add_counter - amount of already added SubHrader rows */

All works right. But problem occures on postback, when GridView restores it's state. First row and all its controls into every group (other words, first row after each dynamically added subheader row) comes without any attributes. But second row in group keeps both its own attributes and attributes of first row.

Some help will be very usefull. Maybe there is another (and right) way to add row into GridView. Then please, provide me with links to tutorials or articles.


Dynamic controls disappear on postback because on postback framework doesn't have information about such controls. It's programmer's responsibility to keep track of these dynamic controls and recreate them after postback...

Please refer to following post for re-creating dynamic controls on postback: FAQ: Why do dynamic controls disappear on postback


Thanks for Waqas. Here is my decision. I override CreateChild(datasource, isBinding) and create list where put index of row, before which you should add subheader row. On SaveViewState i add this list to sealized object. On Load ViewState i load this list and if it's not null create subheader rows by saved indexes. Maybe, there is a simpler and more natural way. But it's hidden from me securely )))

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜