[Solved] Count items in a list – ASP.NET C# [closed]


try this :

protected void btnSearch_Click(object sender, EventArgs e)
{
    string searchWord = txtWord.Text;

    ZaraEntities db = new ZaraEntities();

    var results = db.Products.Where(p => p.Name.Contains(searchWord));

    rptrSearch.DataSource = results.ToList();
    rptrSearch.DataBind();

    litResults.Text = "<p>" + "Search results for " + "'" + txtWord.Text + "'" + " ("+ results.ToList().Count + ") Results found.</p>";

}

OR

litResults.Text = "<p>" + "Search results for " + "'" + txtWord.Text + "'" + " ("+ results.ToList().Count() + ") Results found.</p>";

EDIT :
Even better if you do it like that :

litResults.Text = string.Format("<p>Search results for {0} ({1}) Results found.</p>",txtWord.Text,results.ToList().Count);

4

solved Count items in a list – ASP.NET C# [closed]