Determine number of rows in Repeater?

M

Mike Cain

I'm filling a Repeater control based on a SELECT statement. If the SELECT
statement returns 0 rows, then I want to hide the entire Repeater control.
Currently I'm doing this:

SqlCommand cmd = new SqlCommand("SELECT * FROM whatever where whatever",
conn);

myRepeater1.DataSource =
cmd.ExecuteReader(CommandBehavior.CloseConnection);

So what I'm looking for is now to do this:

if (something == true)

myRepeater1.visible = false;



However I cannot figure ouw what the "something" is above in the IF
statement. What could I use there to either determine that the SQL SELECT
statement returned 0 rows or that the Repeater contained no nows so that I
can dynamically hide the entire repeater includng its header and footer?

Thanks!
 
M

Mark Rae

SqlDataReader objDataReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (!objDataReader.HasRows)
{
myRepeater1.Visible = false;
}
else
{
myRepeater1.DataSource = objDataReader;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top