我的listview和datapager有一些奇怪的问题。我有一个全局搜索(母版页中的搜索字段)
场景1: 用户在我的search.aspx页面以外的任何页面上输入搜索词
结果: 它的工作原理
场景2: 用户正在使用数据寻呼机浏览不同的搜索页面
结果 它的工作原理
场景3:
我在以下datapager方法中进行数据绑定
/// <summary>
/// Set datasource here
/// </summary>
protected void DataPagerProducts_PreRender(object sender, EventArgs e)
{
string searchString = "";
// search cross post handler
if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
{
Page previousPage = PreviousPage;
TextBox tbSearch = (TextBox)PreviousPage.Master.FindControl("txtSearch");
searchString = tbSearch.Text;
}
else if (IsPostBack)
{
TextBox tbSearch = (TextBox)Master.FindControl("txtSearch");
searchString = tbSearch.Text;
}
// validation
if (String.IsNullOrEmpty(searchString) || searchString.Length < 3)
{
return;
}
this.lvSearchResults.DataSource = SetSearchDataSource(searchString);
this.lvSearchResults.DataBind();
}
// paging
protected void lvSearchResults_DataBound(object sender, EventArgs e)
{
dpSearchResults.Visible = (dpSearchResults.PageSize < dpSearchResults.TotalRowCount);
Literal litRecordCount = (Literal)lvSearchResults.FindControl("litRecordCount");
if (litRecordCount != null)
{
litRecordCount.Text = dpSearchResults.TotalRowCount.ToString("#,##0");
}
}
// Item list
protected void lvSearchResults_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
//int channelName = (int)e.Item.DataItem;
Channel channel = (Channel)e.Item.DataItem;
ChannelItem ucChannelItem = (ChannelItem)e.Item.FindControl("ucChannelItem");
}
}