我是asp.net的新手。这是场景。我正在尝试构建搜索功能。如果我在搜索框中输入值,即“测试”并单击搜索图标,SQL Server将返回结果。我的数据页大小有限=“1”。当我点击下一页时它会刷新页面,我的搜索框会丢失我在这种情况下输入的值“Test”。如果没有传递任何值,SQL Server将返回一个默认结果,因此每次我浏览页面时,它只适用于第一页,每次单击后返回默认值。我在数据页的PreRender上绑定列表视图。以下是代码段。
protected void search_ServerClick(object sender, EventArgs e)
{
mydatapager_PreRender(sender, e);
}
protected void mydatapager_PreRender(object sender, EventArgs e)
{
string var_search_firstname = globalsearchinput.Value.ToString();
string var_search_city = citysearchinput.Value.ToString();
string var_search_state = statesearchinput.Value.ToString();
bool isadvancedsearch = false;
//Determine whether it's advanced search or not.
string MethodCaller = "";
//MethodCaller = ((HtmlButton)sender).ID;
//if (MethodCaller == "search")
//{
// isadvancedsearch = false;
//}
//else
//{
// isadvancedsearch = true;
//}
Utility utl = new Utility();
friendrequestsentnotificationpanel.Visible = false;
listview1.DataSource = utl.SearchProfile(var_search_firstname, var_search_city, var_search_state, isadvancedsearch);
listview1.DataBind();
}
答案 0 :(得分:0)
在preRender中添加ispostback==false
条件。它有助于保留serch字符串