在asp.net中手动绑定GridView数据源后?GridView不显示数据?
privatevoidBind(){stringsqlStr="select*fromDepartment";SqlConnectionMyCon=newSqlConne...
private void Bind()
{
string sqlStr = "select * from Department";
SqlConnection MyCon = new SqlConnection(connectionString);
SqlDataAdapter sda = new SqlDataAdapter(sqlStr,MyCon);
DataTable dt = new DataTable();
sda.Fill(dt);
GridView_Department.DataSource = dt;
GridView_Department.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
} 展开
{
string sqlStr = "select * from Department";
SqlConnection MyCon = new SqlConnection(connectionString);
SqlDataAdapter sda = new SqlDataAdapter(sqlStr,MyCon);
DataTable dt = new DataTable();
sda.Fill(dt);
GridView_Department.DataSource = dt;
GridView_Department.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
} 展开
展开全部
你用调试功能调试一下,看看dt里是不是有数据。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
确认表中有数据
追问
有!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private void Bind()
{
string sqlStr = "select * from Department";
SqlConnection MyCon = new SqlConnection(connectionString);
MyCon.Open();
SqlDataAdapter sda = new SqlDataAdapter(sqlStr,MyCon);
DataTable dt = new DataTable();
sda.Fill(dt);
MyCon.close();
GridView_Department.DataSource = dt;
GridView_Department.DataBind();
}
{
string sqlStr = "select * from Department";
SqlConnection MyCon = new SqlConnection(connectionString);
MyCon.Open();
SqlDataAdapter sda = new SqlDataAdapter(sqlStr,MyCon);
DataTable dt = new DataTable();
sda.Fill(dt);
MyCon.close();
GridView_Department.DataSource = dt;
GridView_Department.DataBind();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
开玩笑,都没见你MyCon.open();哪来的数据
追问
哥们,您是幽默呢?还是不懂装懂呢?开个玩笑!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询