2012-07-12 349 views
1

我有兩個動態gridviews在左側和另一個在右側,我綁定這兩個網格上的提交按鈕單擊。動態GridView PageIndexChanging沒有射擊?

我的問題是PageIndexChanging正在爲我點擊第一個,第二個不工作的網格工作ie)如果我先點擊左側網格,PageIndexChanging是單獨爲那個網格工作,而不是爲右側網格和反之。這裏是我的代碼

protected void lnkBTNSubmit_Click(object sender, EventArgs e) 
     { 
      pnlLeft.Controls.Add(grdATASalesTrendleft); 
      dataResult = ObjAnalyzeTrendAnalysis.AnalyzeSalesTrendTables(requestID, "ATAT_1"); 
      dataResult = ObjCommon.GetColumnAliasReportDetails(dataResult, "ATAT_1"); 
      ObjSharedEntities.LeftTableData = dataResult; 
      BindGridDataLeft(grdATASalesTrendleft, ObjSharedEntities.LeftTableData); 
      grdATASalesTrendleft.Visible = true; 

      pnlRight.Controls.Add(grdATASalesTrendright); 
      dataResult = ObjAnalyzeTrendAnalysis.AnalyzeSalesTrendTables(requestID, "ATAT_5"); 
      dataResult = ObjCommon.GetColumnAliasReportDetails(dataResult, "ATAT_5"); 
      ObjSharedEntities.RightTableData = dataResult; 
      BindGridDataRight(grdATASalesTrendright, ObjSharedEntities.RightTableData); 
      grdATASalesTrendright.Visible = true; 
     } 

    protected void Page_Load(object sender, EventArgs e) 
     { 
      GridLoad(); 
     } 

    private void GridLoad() 
     { 
      Leftgrid(); 
      Rightgrid(); 
      BindGridDataLeft(grdATASalesTrendleft, dataResult); 
      BindGridDataRight(grdATASalesTrendright, dataResult); 
     } 

private void Leftgrid() 
     { 
      grdATASalesTrendleft = new GridView(); 
      grdATASalesTrendleft.ID = "grdATASalesTrendleft"; 
      grdATASalesTrendleft.AutoGenerateColumns = true; 
      grdATASalesTrendleft.EmptyDataText = "No data available."; 
      grdATASalesTrendleft.AllowPaging = true; 
      grdATASalesTrendleft.PagerSettings.Mode = PagerButtons.Numeric; 
      grdATASalesTrendleft.PagerSettings.Position = PagerPosition.Bottom; 
      grdATASalesTrendleft.PageSize = 15; 
      grdATASalesTrendleft.PagerStyle.BackColor = System.Drawing.Color.FromArgb(80, 124, 209); 
      ObjCommon.ApplyStylesForGridView(grdATASalesTrendleft); 
      grdATASalesTrendleft.PageIndexChanging += new GridViewPageEventHandler(grdATASalesTrendleft_PageIndexChanging); 
     } 

    private void BindGridDataLeft(GridView e, DataTable dataResult) 
     { 
      GridView grdATASalesTrend = (GridView)e; 
      grdATASalesTrend.DataSource = dataResult; 
      grdATASalesTrend.DataBind(); 
      pnlLeft.Controls.Add(grdATASalesTrend); 
     } 

    void grdATASalesTrendleft_PageIndexChanging(object sender, GridViewPageEventArgs e) 
     { 
     GridView grdATASalesTrendleft = (GridView)sender; 
     grdATASalesTrendleft.PageIndex = e.NewPageIndex; 
     BindGridDataLeft(grdATASalesTrendleft, ObjSharedEntities.LeftTableData); 
     } 

    private void Rightgrid() 
     { 
     grdATASalesTrendright = new GridView(); 
     grdATASalesTrendright.ID = "grdATASalesTrendright"; 
     grdATASalesTrendright.AutoGenerateColumns = true; 
     grdATASalesTrendright.EmptyDataText = "No data available."; 
     grdATASalesTrendright.AllowPaging = true; 
     grdATASalesTrendright.PagerSettings.Mode = PagerButtons.Numeric; 
     grdATASalesTrendright.PagerSettings.Position = PagerPosition.Bottom; 
     grdATASalesTrendright.PageSize = 15; 
     grdATASalesTrendright.PagerStyle.BackColor = System.Drawing.Color.FromArgb(80, 124, 209); 
     ObjCommon.ApplyStylesForGridView(grdATASalesTrendright); 
     grdATASalesTrendright.PageIndexChanging += new GridViewPageEventHandler(grdATASalesTrendright_PageIndexChanging); 
     } 

    private void BindGridDataRight(GridView e, DataTable dataResult) 
     { 
      GridView grdATASalesTrend = (GridView)e; 
      grdATASalesTrend.DataSource = dataResult; 
      grdATASalesTrend.DataBind(); 
      pnlRight.Controls.Add(grdATASalesTrend); 
     } 

    void grdATASalesTrendright_PageIndexChanging(object sender, GridViewPageEventArgs e) 
     { 
     GridView grdATASalesTrendright = (GridView)sender; 
     grdATASalesTrendright.PageIndex = e.NewPageIndex; 
     BindGridDataRight(grdATASalesTrendright, ObjSharedEntities.RightTableData); 
     } 

任何建議嗎?

+0

您是如何註冊活動的? – V4Vendetta 2012-07-12 10:35:05

+0

現在看我的代碼 – Rooney 2012-07-12 10:36:46

回答

2

你想要一個pageindex事件綁定你的網格嗎?我的意思是一個傳呼機點擊兩個網格。如果是這樣,你必須綁定你的兩個網格與新的pageIndex。

void grdATASalesTrendleft_PageIndexChanging(object sender, GridViewPageEventArgs e) 
     { 
     GridView grdATASalesTrendleft = (GridView)sender; 
     grdATASalesTrendleft.PageIndex = e.NewPageIndex; 
     BindGridDataLeft(grdATASalesTrendleft, ObjSharedEntities.LeftTableData); 
     // add 
     grdATASalesTrendright.PageIndex = e.NewPageIndex; 
     BindGridDataRight(grdATASalesTrendright, ObjSharedEntities.RightTableData); 
     } 
+0

編輯我的答案,但我建議你有一個傳呼機爲兩個網格和傳呼機應該從網格分離。你可以從查詢字符串中獲取頁面索引。 – emremp 2012-07-12 11:24:26

+0

這裏的問題是,如果我第一次點擊右側gridview後頁面加載,PageIndexChanging工作正常,但左側gridview PageIndexChanging不工作,如果我點擊左側gridview後頁面加載,PageIndexChanging工作正常,但右側Gridview PageIndexChanging不是工作後,..可以得到我的觀點? – Rooney 2012-07-12 12:24:35

+0

我改變了這個部分grdATASalesTrendright.PageIndexChanging + = new GridViewPageEventHandler(grdATASalesTrendleft_PageIndexChanging); – Rooney 2012-07-12 12:34:08