У меня есть страница поиска с несколькими критериями поиска, а на другой странице отображается результат поиска. Проблема, с которой я сталкиваюсь, заключается в том, что два или более пользователя (другой компьютер или браузер) выполняют поиск на этой странице, на результаты поиска, ранее найденные ранее, влияют результаты нового поиска. в основном результат поиска первичного пользователя заменяется результатом поиска последнего пользователя, когда основной пользователь щелкает по странице или обновляет страницу. Я указал код страницы поиска и страницы результатов поиска.
//code of the search criteria page
protected void btnRegularSrch_Click(object sender, EventArgs e)
{
string strCondition = string.Empty;
string strSql = string.Empty;
string custGender = string.Empty;
string custReli = string.Empty;
string custCaste = string.Empty;
string custMtonge = string.Empty;
string custCountry = string.Empty;
string custAge = string.Empty;
string custMstate = string.Empty;
strSql = "select * from tbl_CustomerInfo cust inner join tbl_Relig rel on rel.regid=cust.REGID inner join tbl_Locat loc on loc.regid=cust.REGID inner join tbl_Photos ph on ph.regid=cust.regid and cust.status=1 ";
//gender
if (Male.Checked)
{
custGender = "m";
}
else
{
custGender = "f";
}
strCondition += " where cust_gender='" + custGender + "'";
//age
if (drp_age_from.SelectedIndex > 0)
{
custAge = drp_age_from.SelectedItem.Text;
if (!string.IsNullOrEmpty(strCondition))
strCondition += "and cust.cust_age between '" + drp_age_from.SelectedItem.Text + "' and '" + drp_age_to.SelectedItem.Text + "'";
else
strCondition += "where cust.cust_age between '" + drp_age_from.SelectedItem.Text + "' and '" + drp_age_to.SelectedItem.Text + "'";
}
//religion
if (ddlSearchReli.SelectedIndex > 0)
{
custReli = ddlSearchReli.SelectedItem.Text;
if (!string.IsNullOrEmpty(strCondition))
strCondition += " and rel.Religion='" + custReli + "'";
else
strCondition += " where rel.Religion='" + custReli + "'";
}
//caste
if (DdlCaste2.SelectedIndex > 0)
{
custCaste = DdlCaste2.SelectedItem.Text;
if (!string.IsNullOrEmpty(strCondition))
strCondition += " and rel.Caste='" + custCaste + "'";
else
strCondition += " where rel.Caste='" + custCaste + "'";
}
//mothertonge
if (ddlCommunty.SelectedIndex > 0)
{
custMtonge = ddlCommunty.SelectedItem.Text;
if (!string.IsNullOrEmpty(strCondition))
strCondition += " and rel.MotherTongue='" + custMtonge + "'";
else
strCondition += " where rel.MotherTongue='" + custMtonge + "'";
}
//country
if (drp_country.SelectedIndex > 0)
{
custCountry = drp_country.SelectedItem.Text;
if (!string.IsNullOrEmpty(strCondition))
strCondition += " and loc.Country='" + custCountry + "'";
else
strCondition += " where loc.Country='" + custCountry + "'";
}
//marital status
if (ddlMStatus.SelectedIndex > 0)
{
strCondition = strCondition + " and (";
custMstate = ddlMStatus.SelectedItem.Text;
if (!string.IsNullOrEmpty(strCondition))
strCondition += " cust.maritalstatus='" + custMstate + "'";
else
strCondition += " where cust.maritalstatus='" + custMstate + "'";
//strCondition = strCondition.TrimEnd(MyChar);
strCondition = strCondition + ")";
}
strSql = strSql + strCondition;
Response.Redirect("SearchResult.aspx?condition=" + Server.UrlEncode(Encrypt(strSql)));
}
//code of the search result page
string conn = ConfigurationManager.ConnectionStrings["con_str"].ConnectionString;
Utility objUtil = new Utility();
static string Condition;
#region Private Properties
private int CurrentPage
{
get
{
object objPage = ViewState["_CurrentPage"];
int _CurrentPage = 0;
if (objPage == null)
{
_CurrentPage = 0;
}
else
{
_CurrentPage = (int)objPage;
}
return _CurrentPage;
}
set { ViewState["_CurrentPage"] = value; }
}
private int fistIndex
{
get
{
int _FirstIndex = 0;
if (ViewState["_FirstIndex"] == null)
{
_FirstIndex = 0;
}
else
{
_FirstIndex = Convert.ToInt32(ViewState["_FirstIndex"]);
}
return _FirstIndex;
}
set { ViewState["_FirstIndex"] = value; }
}
private int lastIndex
{
get
{
int _LastIndex = 0;
if (ViewState["_LastIndex"] == null)
{
_LastIndex = 0;
}
else
{
_LastIndex = Convert.ToInt32(ViewState["_LastIndex"]);
}
return _LastIndex;
}
set { ViewState["_LastIndex"] = value; }
}
#endregion
#region PagedDataSource
PagedDataSource _PageDataSource = new PagedDataSource();
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["condition"] != null)
{
Condition = objUtil.Decrypt(Request.QueryString["condition"]);
this.BindItemsList();
}
}
}
protected DataTable getDataTable()
{
DataUtility objUtil = new DataUtility();
return objUtil.getDataTable(Condition);
//rptViewBasicInfo.DataSource = dt;
//rptViewBasicInfo.DataBind();
}
private void BindItemsList()
{
_PageDataSource.DataSource = this.getDataTable().DefaultView;
_PageDataSource.AllowPaging = true;
_PageDataSource.PageSize = 10;
_PageDataSource.CurrentPageIndex = CurrentPage;
ViewState["TotalPages"] = _PageDataSource.PageCount;
_PageDataSource.PageCount;
this.lbtnPrevious.Enabled = !_PageDataSource.IsFirstPage;
this.lbtnNext.Enabled = !_PageDataSource.IsLastPage;
Repeater1.DataSource = _PageDataSource;
Repeater1.DataBind();
this.doPaging();
}
private void doPaging()
{
DataTable dt = new DataTable();
dt.Columns.Add("PageIndex");
dt.Columns.Add("PageText");
fistIndex = CurrentPage - 5;
if (CurrentPage > 5)
{
lastIndex = CurrentPage + 5;
}
else
{
lastIndex = 10;
}
if (lastIndex > Convert.ToInt32(ViewState["TotalPages"]))
{
lastIndex = Convert.ToInt32(ViewState["TotalPages"]);
fistIndex = lastIndex - 10;
}
if (fistIndex < 0)
{
fistIndex = 0;
}
for (int i = fistIndex; i < lastIndex; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = i + 1;
dt.Rows.Add(dr);
}
this.dlPaging.DataSource = dt;
this.dlPaging.DataBind();
}
//#endregion
protected void lbtnPrevious_Click(object sender, EventArgs e)
{
CurrentPage -= 1;
this.BindItemsList();
}
protected void dlPaging_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals("Paging"))
{
CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
this.BindItemsList();
}
}
protected void dlPaging_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton lnkbtnPage = (LinkButton)e.Item.FindControl("lnkbtnPaging");
if (lnkbtnPage.CommandArgument.ToString() == CurrentPage.ToString())
{
lnkbtnPage.Enabled = false;
lnkbtnPage.Style.Add("fone-size", "14px");
lnkbtnPage.Font.Bold = true;
}
}
protected void lbtnLast_Click(object sender, EventArgs e)
{
CurrentPage = (Convert.ToInt32(ViewState["TotalPages"]) - 1);
this.BindItemsList();
}
protected void lbtnFirst_Click(object sender, EventArgs e)
{
CurrentPage = 0;
this.BindItemsList();
}
protected void lbtnNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
this.BindItemsList();
}