asp.net2.0中的GridView在分頁中出現的錯誤

來源:互聯網
上載者:User
自己封裝了一個gridview控制項,在製作分頁功能時出了一個錯誤,比較有意思。
這是錯誤碼,在gridView執行DataBind函數的時候。
  at System.Web.UI.WebControls.GridView.BuildCallbackArgument(Int32 pageIndex)
  at System.Web.UI.WebControls.GridView.CreateNumericPager(TableRow row, PagedDataSource pagedDataSource, Boolean

addFirstLastPageButtons)
  at System.Web.UI.WebControls.GridView.InitializePager(GridViewRow row, Int32 columnSpan, PagedDataSource

pagedDataSource)
  at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType

rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields,

TableRowCollection rows, PagedDataSource pagedDataSource)
  at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
  at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
  at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
  at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
  at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback

callback)
  at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
  at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
  at System.Web.UI.WebControls.GridView.DataBind()
  at Maxplatform.UI.Web.Controls.EntityGrid.BindData(Object parent) in
看上去,好像是在建立頁號的時候出錯了。提示是“未將對象應用到執行個體”。
使用這個控制項時的代碼
                            EntityGrid grid = new EntityGrid();
                            grid.BindData(this);
                            cell.Controls.Add(grid);

但是在測試時,gridview分頁沒有問題,問題出在哪裡呢? 
這是運行正確時gridview產生的html代碼,它使用js執行callback
                     
<a href="javascript:__doPostBack('ctl01$cph_webpart_manager$WPM$VE_viewplace$view_common_grid$ctl13$ctl02','')">第2頁</a>

js:__doPostBack函數是使用控制項的路徑來callback的:'ctl01$cph_webpart_manager$WPM$VE_viewplace$view_common_grid$ctl13$ctl02'。這就是關鍵的地方。

前一個出錯就是出在這裡:路徑有錯誤。因為這兩句代碼的緣故:
                            grid.BindData(this);
                            cell.Controls.Add(grid);
也就是,現綁定,在把控制項載入到父控制項上時,js構造路徑出錯。

反過來這樣處理  :
                          cell.Controls.Add(grid);
                          grid.BindData(this);
也就是先放置控制項,確定它的路徑,然後再綁定,讓js產生callback的代碼,結果,剛才的異常消失了。

關鍵的問題是:
gridview是在databind()中立即用來構建js回調的路徑。

文章來源:http://blog.aspcool.com/dlwang2002/archive/2005/08/05/2615.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.