0

I have ListView with paging and EntityDataSource. ListView should show all items from database but If in url we have for example phrase 'cat' it should show only items with phrase 'cat' in Title so I have:

public partial class List : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["phrase"] != null)
        {
            EntityDataSource1.WhereParameters.Add("Phrase", TypeCode.String, Request.QueryString["phrase"].ToString());
            EntityDataSource1.Where = "it.Title like '%' + @Phrase + '%'";
        }
    }
}

But when I go to next page I have error: Parameter name "Phrase" already exists in the parameter collection

What can I do?

4

1 に答える 1

1
EntityDataSource1.WhereParameters.Clear();

EntityDataSource1.WhereParameters.Add("Phrase", TypeCode.String, '%' + Request.QueryString["phrase"].ToString() +'%'");
EntityDataSource1.Where = "it.Title LIKE @Phrase";

また

EntityDataSource1.Where = "it.Title LIKE @Phrase";
EntityDataSource1.WhereParameters["Phrase"].DefaultValue
    =  '%' + Request.QueryString["phrase"].ToString() +'%'";
于 2013-06-08T12:18:29.830 に答える