日期:2014-05-18  浏览次数:20448 次

我想在一个GridView的下面加一个底部页导航条,为什么会报错?
public   partial   class   _Default   :   System.Web.UI.Page  
{
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                if   (!IsPostBack)
                {
                        GridView1.DataSource   =   SqlDataSource1;
                        GridView1.DataBind();
                }

        }
        protected   void   GridView1_DataBound(object   sender,   EventArgs   e)
        {
                GridViewRow   bottomRow   =   GridView1.BottomPagerRow;
                Label   lb   =   new   Label();
                lb.Text   =   "sss ";
                bottomRow.Cells[0].Controls.Add(lb);
        }
}
aspx里就拉了一个SqlDataSource,一个GridView
调试时
bottomRow.Cells[0].Controls.Add(lb);
报错:在未将对象引用设置到对象的实例
why?

------解决方案--------------------
冲这句 贴--出了名的快)

你的pageload事件中无须指定gridview1的datasource属性.

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Select Case e.Row.RowType
Case DataControlRowType.Pager
Dim l As New Label
l.Text = "Test "
e.Row.Cells(0).Controls.Add(l)
End Select
End Sub
------解决方案--------------------
对应该在RowDataBound事件里添加
------解决方案--------------------
没有什么问题啊
------解决方案--------------------
GridView1.DataSource = SqlDataSource1;

==========

使用 xxxDataSource 控件,应该将它的ID给 GridView.DataSourceID属性

<asp:GridView ID= "GridView1 " DataSourceID= "SqlDataSource1 " ....