Object reference error in gird view paging for wss webpart

Aug 6, 2008 at 1:18 PM
 in custom webpart i would like to create gridview with paging , the following code is throughing the Object reference not set to an instance of an object at the line of gv1.DataBind();

gv1 = new SPGridView();
gv1.AllowPaging = true;
gv1.PageSize = 3;
gv1.DataSource = dtInternal;
gv1.PageIndexChanging += new GridViewPageEventHandler(gv1_PageIndexChanging);
gv1.DataBind();    (here i am getting object reference error)




gv1_PageIndexChanging(object sender, GridViewPageEventArgs e)
gv1.PageIndex = e.NewPageIndex;

private void BindEvents()
gv1.DataSource = dtInternal;