网格视图在运行时不显示最上面的行
本文关键字:显示 视图 运行时 网格 | 更新日期: 2023-09-27 17:57:45
首次发布,长期搜索。我相信这是一个简单的解决方案。。。。但我在这里撞到头了。使用visual studio 2012
我有一个网格视图,它在代码后面使用sql进行行数据绑定。问题是,当我运行它时,第一行不会显示在网格视图上。这些数据是非常动态的,并且不断变化。有什么建议吗?
代码:
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();
}
网格视图中是否存在可能导致此问题的属性?gridview是RowDatabound,并且有代码来处理它。我只是觉得它的属性有些愚蠢。
谢谢!
使用reader1.Read()命令,跳过第一行,改为
using (SqlDataReader reader = cmd.ExecuteReader())
{
DataTable table = new DataTable();
table.Load(reader);
GridView1.DataSource = table;
}