在Asp.net 4.0(C#)中,在启用分页的网格中,当我们从另一个页面导航回来时,如何保留文本框值?
即使我在网格中的多个页面中导航,我也必须保留文本框值。
请为我提供最简单的解决方案。
这是代码:
protected void grdSgnageEntries_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
DataSet ds = new DataSet();
lblErrorMessage.Text = string.Empty;
int JkpId = 0, LinkLevelId = 0;
if (Convert.ToInt32(ddlSnapShotType.SelectedValue.ToString()) == (int)SnapshotTypes.JackpotHit)
{
JkpId = Convert.ToInt32(ddlJackpotInstances.SelectedValue.ToString());
LinkLevelId = Convert.ToInt32(ddlLevels.SelectedValue.ToString());
}
grdSgnageEntries.PageIndex = e.NewPageIndex;
FillSgnageEntriesGrid(LinkLevelId, JkpId);
grdSgnageEntries.DataBind();
}
catch (FormatException exp)
{
lblErr.Text = "Invalid Date";
grdSgnageEntries.DataSource = null;
grdSgnageEntries.DataBind();
btnSubmit.Visible = false;
}
catch (Exception exp)
{
bc.LogExceptionToDB(exp);
}
}
protected void grdSgnageEntries_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((TextBox)e.Row.FindControl("txtAmount")).Attributes.Add("onkeypress", "javascript:return MyKeyPress();");
if (((TextBox)e.Row.FindControl("txtAmount")).Text != string.Empty)
{
((TextBox)e.Row.FindControl("txtAmount")).Enabled = false;
btnValidate.Enabled = false;
}
else
{
btnValidate.Enabled = true;
}
}
}
catch (Exception exp)
{
bc.LogExceptionToDB(exp);
}
}
protected void btnGetLevels_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds = bc.getJackpotInstancesForSignageEntry(Convert.ToInt32(ddlLinks.SelectedItem.Value), Convert.ToDateTime(txtEntryDate.Text.ToString()), Convert.ToInt32(ddlSnapShotType.SelectedValue.ToString()), LinkLevelId, JkpId);
Session["gamingDate"] = Convert.ToDateTime(txtEntryDate.Text.ToString());
if (ds.Tables.Count > 1)
{
grdSgnageEntries.Columns[0].Visible = true;
grdSgnageEntries.DataSource = ds.Tables[2];
grdSgnageEntries.DataBind();
grdSgnageEntries.Columns[0].Visible = false;
btnSubmit.Visible = true;
btnValidate.Visible = true;
btnSubmit.Enabled = false;
}
}
答案 0 :(得分:0)
您可以在会话中存储数据,例如:
// Save before going to another page:
Session["FirstName"] = FirstNameTextBox.Text;
// Load when coming back to the page:
FirstNameTextBox.Text = (string)Session["FirstName"];
此处有更多详情:ASP.NET Session State Overview