如果回发,如何保留页面内容 [英] How to keep the page contents if it is posted back

查看:53
本文介绍了如果回发,如何保留页面内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要保留网格视图,该网格视图是在发回页面ID时在文本字段中按ID搜索的结果。为了说明,我有网格视图表上的链接带我到另一个页面然后我在页面链接返回该网格视图未找到,因为页面在发回。





请帮助



  //   pageload  
protectedvoidPage_Load(objectsender,EventArgse)
{
缓存[ MId] = TextBox7.Text;
if (TextBox7.Text!= null
{
view_back();
rep_bind();
}
if (IsPostBack)
{
label10.Text = ;
view_back();
Cache [ MId] = TextBox7.Text;
grid.Visible = true ;
}
}
// searchcode
protectedvoidSearch (objectsender,EventArgse)
{
if (TextBox7.Text!= null
{
SqlConnectioncon1 = newSqlConnection(ConfigurationManager.ConnectionStrings [ ConnectionString] .ConnectionString);
con1.Open();
stringquery = SElECtt1。*,t2。*,t3。* fromdbo.MaterialASt1INNERJOINdbo.ModuleRelationAst2ONt2.MID = t1.MIDINNERJOINdbo.UsersASt3ONt3.UniID = t2.UIdwheret3.user_type ='Staff'andt1.IsDeleted = 0ANDt2.MID =' + TextBox7.Text + ';
SqlCommandcom = newSqlCommand(query,con1);
SqlDataReaderdr;
dr = com.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
rep_bind();
label10.Text = ;
grid.Visible = true ;
}
if (!dr.HasRows)
{
label10.Text = ModuleIDNotFound!;
grid.Visible = false ;
}
}
}
// methodfordisplayinggridview
privatevoidrep_bind()
{
if (TextBox7.Text!= null
{
SqlConnectioncon1 = newSqlConnection(ConfigurationManager.ConnectionStrings [ ConnectionString]的ConnectionString);
con1.Open();
stringquery = SElECtt1。*,t2。*,t3。* fromdbo.MaterialASt1INNERJOINdbo.ModuleRelationAst2ONt2.MID = t1.MIDINNERJOINdbo.UsersASt3ONt3.UniID = t2.UIdwheret3.user_type ='Staff'andt1.IsDeleted = 0ANDt2.MID =' + TextBox7.Text + ';
SqlDataAdapterda = newSqlDataAdapter(query,con1);
DataSetds = newDataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
// forclickonviewlinkongridviewtoredirecttoaontherpage
publicvoidView ()
{
Response.Redirect( View.aspx?Id = +(MAID));
}
// thisIdidtokeepthecontentsofthepagewhenitloadedandIcalledinloadmethodbutnotworkingjustitkeepserrormessageforif(!dr.HasRows)
privatevoidview_back()
{
if (TextBox7.Text!= null
{
SqlConnectioncon1 = newSqlConnection(ConfigurationManager.ConnectionStrings [ ConnectionString]。ConnectionString );
con1.Open();
stringquery = SElECtt1。*,t2。*,t3。* fromdbo.MaterialASt1INNERJOINdbo.ModuleRelationAst2ONt2.MID = t1.MIDINNERJOINdbo.UsersASt3ONt3.UniID = t2.UIdwheret3.user_type ='Staff'andt1.IsDeleted = 0ANDt2.MID =' + TextBox7.Text + ';
SqlCommandcom = newSqlCommand(query,con1);
SqlDataReaderdr;
dr = com.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
rep_bind();
label10.Text = ;
grid.Visible = true ;
}
if (!dr.HasRows)
{
label10.Text = ModuleIDNotFound!; // 此信息显示在页面上
grid.Visible = false ;
}
}
}

解决方案

你的方法看起来不错,你有什么错误吗?这样做?



请参考

asp.net - 在离开Gridview页面后维护GridView当前页面索引 - Stack Overflow [ ^ ]

I need to keep the grid view which appears as a result of searching by id in the text field when the page id posted back. To illustrate, I have the link on grid view table takes me to another page then I have on the page link go back that grid view is not found because the page in posted back.


please help

//pageload
protectedvoidPage_Load(objectsender,EventArgse)
{
Cache["MId"]=TextBox7.Text;
if(TextBox7.Text!=null)
{
view_back();
rep_bind();
}
if(IsPostBack)
{
label10.Text="";
view_back();
Cache["MId"]=TextBox7.Text;
grid.Visible=true;
}
}
//searchcode
protectedvoidSearch(objectsender,EventArgse)
{
if(TextBox7.Text!=null)
{
SqlConnectioncon1=newSqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con1.Open();
stringquery="SElECtt1.*,t2.*,t3.*fromdbo.MaterialASt1INNERJOINdbo.ModuleRelationAst2ONt2.MID=t1.MIDINNERJOINdbo.UsersASt3ONt3.UniID=t2.UIdwheret3.user_type='Staff'andt1.IsDeleted=0ANDt2.MID='"+TextBox7.Text+"'";
SqlCommandcom=newSqlCommand(query,con1);
SqlDataReaderdr;
dr=com.ExecuteReader();
if(dr.HasRows)
{
dr.Read();
rep_bind();
label10.Text="";
grid.Visible=true;
}
if(!dr.HasRows)
{
label10.Text="ModuleIDNotFound!";
grid.Visible=false;
}
}
}
//methodfordisplayinggridview
privatevoidrep_bind()
{
if(TextBox7.Text!=null)
{
SqlConnectioncon1=newSqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con1.Open();
stringquery="SElECtt1.*,t2.*,t3.*fromdbo.MaterialASt1INNERJOINdbo.ModuleRelationAst2ONt2.MID=t1.MIDINNERJOINdbo.UsersASt3ONt3.UniID=t2.UIdwheret3.user_type='Staff'andt1.IsDeleted=0ANDt2.MID='"+TextBox7.Text+"'";
SqlDataAdapterda=newSqlDataAdapter(query,con1);
DataSetds=newDataSet();
da.Fill(ds);
GridView1.DataSource=ds;
GridView1.DataBind();
}
}
//forclickonviewlinkongridviewtoredirecttoaontherpage
publicvoidView()
{
Response.Redirect("View.aspx?Id="+(MaID));
}
//thisIdidtokeepthecontentsofthepagewhenitloadedandIcalledinloadmethodbutnotworkingjustitkeepserrormessageforif(!dr.HasRows)
privatevoidview_back()
{
if(TextBox7.Text!=null)
{
SqlConnectioncon1=newSqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con1.Open();
stringquery="SElECtt1.*,t2.*,t3.*fromdbo.MaterialASt1INNERJOINdbo.ModuleRelationAst2ONt2.MID=t1.MIDINNERJOINdbo.UsersASt3ONt3.UniID=t2.UIdwheret3.user_type='Staff'andt1.IsDeleted=0ANDt2.MID='"+TextBox7.Text+"'";
SqlCommandcom=newSqlCommand(query,con1);
SqlDataReaderdr;
dr=com.ExecuteReader();
if(dr.HasRows)
{
dr.Read();
rep_bind();
label10.Text="";
grid.Visible=true;
}
if(!dr.HasRows)
{
label10.Text="ModuleIDNotFound!";//thisappearswhenthepageispostedback
grid.Visible=false;
}
}
}

解决方案

Your Approach looks good, did you get any errors while doing so?

please refer
asp.net - Maintaining GridView current page index after navigating away from Gridview page - Stack Overflow[^]


这篇关于如果回发,如何保留页面内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆