Friday, June 5, 2009

Asp.Net Gridview notes

Some notes on things I encountered recently. Will put some sample code once I am done with current project and have a stable code

  1. Gridview OnRowBound event is fired when we do gridview.databind(); When we do a postback the data in the gridview is displayed using viewstate if gridview viewstate is enabled, but any formatting done in OnRowBound is lost.
  2. If you have dynamically generated controls in gridview header (dropdownlist, textbox etc), it's better to put the code that generates the controls in gridview RowCreated event, since it'll get fired even when postback.
  3. To sort gridview we need to have a SortExpression bind to a boundField. We then have a method to handle GridViewSortEvent.

No comments: