user3515669
user3515669

Reputation: 1

Gridview doesnt show top most row on Run

first time poster, long time searcher. I'm sure this is a simple fix....but i'm banging my head here. using visual studio 2012

I have a gridview thats rowdatabound using sql in the code behind. The issue is, the first row doesnt show on the gridview when i run it. This data is extremely dynamic and constantly changes. Any suggestions?

Code:

sql2 = "select cf.cfs_no, us.unit_id, ua.unit_activity_description, ct.call_description, cf.premise_name, us.location " +
                           "from dba.units_service us with(nolock) " +
                            "left outer join dba.cfs cf with(nolock) on " +
                            "us.cfs_key = cf.cfs_key " +
                            "left outer join dba.call_type ct with(nolock) on " +
                            "cf.call_type = ct.call_type_cd " +
                            "left outer join dba.unit_activity ua with(nolock) on " +
                            "us.unit_activity_cd = ua.unit_activity_cd " +
                            "where " +
                            "(agency_id in (@agency_id) and us.unit_activity_cd != @unit_activity) " +
                            "order by 1 desc, 2 desc ";

                    //agency_id = @varrible ; us.unit_activity_cd = @varrible

                    using (SqlCommand cmd = new SqlCommand(sql2, con))
                    {
                        //con.Open();
                        SqlDataReader reader1 = cmd.ExecuteReader();
                        //SqlDataAdapter da = new SqlDataAdapter(cmd);

                        if (reader1.HasRows)
                        {
                            reader1.Read();
                            GridView1.DataSource = reader1;
                            GridView1.DataBind();
                        }

Is there a property in the gridview that maybe causing this? The gridview is RowDatabound and has code to handle it. I just think its something silly with the properties.

Thanks!

Upvotes: 0

Views: 40

Answers (1)

CuriousPen
CuriousPen

Reputation: 249

By using reader1.Read() command, you skip the first row, try this instead

using (SqlDataReader reader = cmd.ExecuteReader())
{
    DataTable table = new DataTable();
    table.Load(reader);
    GridView1.DataSource = table;
}

Upvotes: 1

Related Questions