I am using asp.net GridView for displaying data, I have 9 columns coming from Database,from which I have to hide last two columns and records of those. I am using GridView RowDatabound event for hiding the columns and records. Its working fine when I am running my application from VS, even when I publish it on local IIS, it is working fine, but when I deployed it live, its giving following exception:
Object reference not set to an instance
I am using same database for both publishes Here's my code
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView1.HeaderRow.Cells[7].Visible = false;
GridView1.HeaderRow.Cells[8].Visible = false;
e.Row.Cells[7].Visible = false;
e.Row.Cells[8].Visible = false;
}
}
Databinding is done with DataTable
var data = MyClass.GetHistory();//it returns DataTable
GridView1.DataSource = data;
GridView1.DataBind();