2012-07-12 401 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