I use GridView1_RowCreated1 to change font and backcolor for some fields upon certain conditions for the gridView. It works fine when the gridView is loaded first time. I rebind the gridview every time when the page is loaded.
I also have a table above the gridView with a submit button and serveral input fields which are passed to the gridView as its sqldatasource parameters served as filters for the list of gridView data. When the page is loaded first time, the gridview is not loaded. When the submit button is clicked, the gridView is loaded. This works fine too.
However, after the griveView is loaded, I can neither sort the gridview nor submit again with same or different input values as filters. The sorting and filters worked fine before I added the gridView1_RowCreated1 sub.
The error message I got is:
Object reference not set to an instance of an object.
Object reference not set to an instance of an object.
DataBinder.Eval(e.Row.DataItem, "myDataBindField") 'the line is within the GridView1_RowCreated1 sub and causes the error.
I think the problem is after the first time the gridView is loaded, the rows have been created. So when the page is postback again, the rows are not created again, which causes this error message.
How to fix?