我有两个动态网格视图,一个位于左侧,另一个位于右侧,并在点击提交按钮时绑定这两个网格。
我的问题是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 :(得分: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);
}