1

我有两个动态网格视图,一个在左侧,另一个在右侧,并且在单击提交按钮时绑定这两个网格。

我的问题是PageIndexChanging 适用于我首先单击的网格,而第二个不起作用即)如果我先单击左侧网格,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);
       }

有什么建议吗?

4

1 回答 1

3

您想要一个 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);
       }
于 2012-07-12T10:56:46.083 回答