Hi all,
i got some errors while am creating search option in my application , in this am handling asp.net application using c#.The thing is i enter some text in my textbox and i click search button its working fine, but without entering anything in the textbox and click search button ,its showing following error,
"String cannot be of zero length.
Parameter name: oldV
click event code,
protected void imgSearch_Click(object sender, ImageClickEventArgs e)
{
Session.Add("searchterm", txtSearch.Text.Trim());
Response.Redirect("cheers_search-result.aspx");
}
please see my below source code and let me know if any solution
clsOleCon objOle = new clsOleCon();
System.Text.StringBuilder strtodisplay = new System.Text.StringBuilder();
protected void Page_Load(object sender, EventArgs e)
{
string searchterm = Session["searchterm"].ToString();
string query = "SELECT * from content where contents like '%" + searchterm + "%';";
DataTable dt = objOle.selectquery(query);
if (dt.Rows.Count > 0)
{
strtodisplay.Append("
"); foreach (DataRow dr in dt.Rows) { string resultant = ""; if (dr.ItemArray[1].ToString().Length > 150) { resultant = dr.ItemArray[1].ToString().Remove(150, (dr.ItemArray[1].ToString().Length - 150)); resultant = resultant.ToLower(); resultant = resultant.Replace(searchterm, "" + searchterm + ""); // resultant = resultant.Replace(searchterm, "" + searchterm + ""); } else { resultant = dr.ItemArray[1].ToString(); resultant = resultant.Replace(searchterm, "" + searchterm + ""); } resultant = resultant + " ...."; strtodisplay.Append(""); strtodisplay.Append(""); strtodisplay.Append(""); } strtodisplay.Append("
");
lblSearchresult.Text = strtodisplay.ToString();
}
else
{
strtodisplay.Append("
"); strtodisplay.Append("No Matches found"); strtodisplay.Append(" |
");
lblSearchresult.Text = strtodisplay.ToString();
}
}
thanks in advance