【发布时间】:2018-01-18 09:24:36
【问题描述】:
我尝试制作一个从数据库中检索 xml 数据的 Web 应用程序。 数据库将第一页 Gridview 与复选框绑定: First page
这个页面的网址是http://localhost:65224/WebForm1.aspx
“验证”按钮重定向的第二页是第一页中所选项目的结果,其中包含您所选内容的更多详细信息: Page Results
我不知道为什么,但是URL和最后一个一样:http://localhost:65224/WebForm1.aspx
最后一个“验证”按钮是确认您要更新的内容,我想打开一个新页面以确认用户从复选框(摘要)中选择了什么,但第三页完全是空的。 而且,第三页的 URL 最后是正确的:http://localhost:65224/WebForm3.aspx
第二页后面有代码,这就是为什么我有结果,但我不知道为什么 URL 不正确。
这是 WebForm2 的“OnClick”按钮后面的代码:
protected void btn_final_validation_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm3.aspx");
foreach (GridViewRow row in gvResult.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("FinalChk");
CheckBox cb2 = (CheckBox)row.FindControl("FinalChkForm");
if ((cb != null && cb.Checked) || (cb2 != null && cb2.Checked))
{
Server.Transfer("~/WebForm3.aspx");
//cb2.Visible = false;
//Response.Redirect("WebForm3.aspx");
}
else
{
//ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Veuillez sélectionner au moins un item')", true);
Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Vous devez sélectionnere au moins 1 item.');</script>");
}
}
foreach (GridViewRow row in gvResultForm.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("FinalChkForm2");
if (cb != null && cb.Checked)
{
Server.Transfer("~/WebForm3.aspx");
}
}
foreach (GridViewRow row in gvResultFormSelected.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("FinalChk2");
if (cb != null && cb.Checked)
{
Server.Transfer("~/WebForm3.aspx");
}
}
}
这是 WebForm3 的 Page_Load 代码:
protected void Page_Load(object sender, EventArgs e)
{
List<string> test_recup = new List<string>();
if (this.Page.PreviousPage != null)
{
GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("gvResult");
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[0].FindControl("FinalChk") as CheckBox);
CheckBox chkRow2 = (row.Cells[2].FindControl("FinalChkForm") as CheckBox);
if (chkRow.Checked)
{
string name = row.Cells[1].Text;
test_recup.Add(name);
System.Diagnostics.Debug.WriteLine("Template selected : " + name);
}
}
}
}
DataTable dt = new DataTable();
dt.Columns.Add("recup_template", typeof(string));
foreach (string s in test_recup)
{
dt.Rows.Add(s);
System.Diagnostics.Debug.WriteLine("test : " + s);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
【问题讨论】:
标签: c# asp.net navigation