M
maggie
hi,
I have a gridview that is based on parameters. When the select statement
does not return any rows, I want to display a label that says 'nothing
found'. It works the first time there is not data, but after that, it
displays what the previous select statement retrieved. How do I fix it so
that it doesn't do that? I am using a datareader. This is my code:
I have a gridview that is based on parameters. When the select statement
does not return any rows, I want to display a label that says 'nothing
found'. It works the first time there is not data, but after that, it
displays what the previous select statement retrieved. How do I fix it so
that it doesn't do that? I am using a datareader. This is my code:
Code:
cn.Open();
System.Data.SqlClient.SqlDataReader dr ;
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
GridView1.DataSource = dr;
GridView1.DataBind();
}
lblNoData.Visible = (GridView1.Rows.Count == 0);
dr.Close();
cn.Close();
}