如何计算searchResult的数量 [英] How to count number of searchResult

查看:90
本文介绍了如何计算searchResult的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,

这是根据用户填写的多个条件进行搜索查询的代码.我触发此查询并将结果存储在数据表中,并将该数据表存储在会话中,然后将该会话撤到另一页上,以在listview中显示搜索结果.

我的问题是,我想计算此查询返回的记录数,并在
的搜索结果页面上显示它们 例如:找到25条记录,或者如果未找到记录则显示未找到记录 ..

Sir,

This is code for Search Query on multiple criteria filled by user. I am firing this query and storing result in datatable and storing that datatable in session and retreving this session on another page to display search result in listview.

My problem is that, I want to count the number of records return by this query and display them on search Result page on top for
eg: 25 Records found or if no record found display no record found..

SqlConnection con = new SqlConnection(str);
            string strQ = ("select s.Property_ID,s.Property_For,s.Property_Type,s.Property_Name,C.City_Name,L.Locality_Name,s.Price,s.Bedroom,s.Area,s.ImageName,s.ImagePath From tbl_Post_Property as s inner join tbl_City as C on C.City_Id=s.City_id inner join tbl_Locality as L on L.Locality_Id=s.Locality_Id where Property_For='"+ rbtnsearch.SelectedItem.Text +"' and s.Property_type='" + ddlpropertytype.SelectedItem.Text + "' and C.City_Id=" + ddlcity.SelectedValue + " and L.Locality_Id=" + ddllocality.SelectedValue + " and s.price between " + ddlminprice.SelectedValue + " and " + ddlmaxprice.SelectedValue + "");
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter(strQ, con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            Session["Search"] = dt;
            con.Close();
            Response.Redirect("SearchResult.aspx", false);


搜索结果页面


Searchresult Page

DataTable dt = new DataTable();
        dt = Session["Search"] as DataTable;         
        listview1.DataSource = dt;
        listview1.DataBind();

推荐答案

int rowcount = dt.rows.count();


将为您提供获取的记录数.


will give you the number of records fetched.


您可以在文件的顶部放置一个标签,并像这样设置值..

you can put a label on the top of your flied and set the the value like this..

Label1.Text = Covert.ToString(dt.Rows.Count)+"Records found ";



如果您需要将消息设置为零行,则可以使用条件条件.



you can use conditional staement if you need to set message for zero rows


使用以下代码.
Use the code as below.
if(dt.Rows.Count > 0)
{
     lblSearchResultText.Text = Covert.ToString(dt.Rows.Count) + " Records found.";
}
else
{
     lblSearchResultText.Text = "No records found.";
}


这篇关于如何计算searchResult的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆