我正在编辑一些不是由我自己编写的代码,而是一些不再在这里的代码。
我正在编辑的页面有三个选项卡,每个选项卡包含一个不同的网格视图,该视图由选项卡中的搜索框填充。网格视图中的每一行都有一个复选框。按下打印按钮时,应打印复选框中带有勾号的所有记录。然后页面重新加载,但由于页面编码的方式,一些内容丢失。
这是因为某些代码仅在单击选项卡而不是回发时调用。无论如何我是否更改了以下代码,以便在回发后调用它?
这些是造成最大问题的函数..我需要在回发时加载正确的选项卡。我无法为所有三个执行此操作,因为在这种情况下代码需要永远运行。
AddActionsToGridView(gvGlobal); AddCheckboxesToGridView(gvGlobal);
{
if (tabconConsignments.ActiveTabIndex == 0)
{
dtGlobalIDConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "GlobalID", "", "");
//Global ID Tab
gvGlobal.DataSource = dtGlobalIDConsignments;
gvGlobal.DataBind();
//Actions
AddActionsToGridView(gvGlobal);
AddCheckboxesToGridView(gvGlobal);
}
else if (tabconConsignments.ActiveTabIndex == 1)
{
dtCreatedDateConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "CreatedDate", "", "");
//Created Date Tab
gvCreationDate.DataSource = dtCreatedDateConsignments;
gvCreationDate.DataBind();
tbCreationDateSearch.Text = "";
//Actions
AddActionsToGridView(gvCreationDate);
AddCheckboxesToGridView(gvCreationDate);
}
else if (tabconConsignments.ActiveTabIndex == 2)
{
dtAccountsConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "Account", "", "");
//Account Tab
gvAccount.DataSource = dtAccountsConsignments;
gvAccount.DataBind();
AddActionsToGridView(gvAccount);
AddCheckboxesToGridView(gvAccount);
}
如果您希望我发布任何更多代码或更多信息,请告诉我这对我来说是个难以理解的问题,所以我可能会遗漏一些东西。感谢您提供任何帮助。
答案 0 :(得分:0)
很难说我是否回答你的问题,因为主题标题似乎与内容有点不同。您是否只是尝试将代码移动到在回发期间而不是在选项卡单击事件期间调用的位置?如果是这样,只需将其移动到页面加载事件并指定您希望它仅在回发期间运行,如下所示:
protected void Page_Load(object sender, EventArgs e)
{
if(this.Page.IsPostBack)
{
switch (tabconConsignments.ActiveTabIndex)
{
case 0:
// Do your stuff here.
break;
case 1:
// Do your stuff here.
break;
case 2:
// Do your stuff here.
break;
default:
// Do your stuff here.
break;
}
}
}
答案 1 :(得分:0)
我会想象这样的事情
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
SetTabGrids(();
}
protected void btnPrint_Click(object sender, EventArgs e)
{
//Code
SetTabGrids();
}
protected void tabconConsignments_TabIndexChanged(object sender, EventArgs e)
{
//Code
SetTabGrids();
}
private void SetTabGrids()
{
switch(tabconConsignments.ActiveTabIndex)
case 0: //Global ID Tab
dtGlobalIDConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "GlobalID", "", "");
gvGlobal.DataSource = dtGlobalIDConsignments;
gvGlobal.DataBind();
AddActionsToGridView(gvGlobal);
AddCheckboxesToGridView(gvGlobal);
break;
case 1: //Created Date Tab
dtCreatedDateConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "CreatedDate", "", "");
gvCreationDate.DataSource = dtCreatedDateConsignments;
gvCreationDate.DataBind();
tbCreationDateSearch.Text = "";
AddActionsToGridView(gvCreationDate);
AddCheckboxesToGridView(gvCreationDate);
break;
case 2:
dtAccountsConsignments = fGenerateTableSQL(astrPalletIDs, DateFrom, DateTo, ddlReqColDel.SelectedValue, "Account", "", "");
gvAccount.DataSource = dtAccountsConsignments;
gvAccount.DataBind();
AddActionsToGridView(gvAccount);
AddCheckboxesToGridView(gvAccount);
break;
}
}
首次加载页面时,通过调用SetTabGrids()方法执行网格绑定。之后,确保在处理PostBack for PrintButtonClick和TabIndexChange时调用SetTabGrids。