Victor_Tlepshev
Victor_Tlepshev

Reputation: 510

Search page with empty TextBox returns - Null or empty full-text predicate

I work on a search page. I am using 2 repeaters. First to display the results of the search and second to display paging.

The query works just fine if I exclude postback. I can type something in the search box and it appears on the screen. Without the postback, the problem is when I click to go to the second page, I lose the paging repeater. That means I cannot go back to the first page.

So I need this postback to work.

The problem is when the page first loads the text box is empty, therefore I get the following error: "Null or empty full-text predicate."

How to get around it?

Here my code:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindRpt();
    }
}
private void BindRpt()
{ 
    SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["blabla"].ConnectionString);
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = cn;
    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
    cmd.CommandText = "select Distinct Rank, columnA, columnB, columnC from FREETEXTTABLE (TABLE, columnA , '" + Search.Text + "'  ) S, TABLE C WHERE c.columnID = S.[KEY] order by Rank Desc";

    DataTable dt = new DataTable();
    adapter.SelectCommand = cmd;
    adapter.Fill(dt);

    PagedDataSource pgitems = new PagedDataSource();
    pgitems.DataSource = dt.DefaultView;
    pgitems.AllowPaging = true;

    pgitems.PageSize = 2;
    pgitems.CurrentPageIndex = PageNumber;
    if (pgitems.Count > 1)
    {
        rptPaging.Visible = true;
        ArrayList pages = new ArrayList();
        for (int i = 0; i <= pgitems.PageCount - 1; i++)
        {
            pages.Add((i + 1).ToString());
        }
        rptPaging.DataSource = pages;
        rptPaging.DataBind();
    }
    else 
    {
        rptPaging.Visible = false;
    }
    rptResults.DataSource = pgitems;
    rptResults.DataBind();
}
public int PageNumber
{ 
    get
    {
        if(ViewState["PageNumber"] != null)
        {
            return Convert.ToInt32(ViewState["PageNumber"]);
        }
        else
        {
            return 0;
        }
    }
    set 
    { ViewState["PageNumber"] = value; }
}
protected void rptPaging_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
    PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
    BindRpt();
}
protected void btnGo_Click(object sender, EventArgs e)
{
    BindRpt();
}

Upvotes: 1

Views: 207

Answers (2)

PratikDotCa
PratikDotCa

Reputation: 174

Update following condition:

if (pgitems.Count > 1)

to

if (pgitems.Count > 0)

Upvotes: 0

Rob Epstein
Rob Epstein

Reputation: 1500

Try adding the following as the first line of BindRpt()

if (string.IsNullOrEmpty(Search.Text)) return;

Upvotes: 1

Related Questions