我的程序:
GridView1.Rows(0).Cells(0).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim()
GridView1.Rows(0).Cells(1).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim()
GridView1.Rows(0).Cells(2).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim()
GridView1.Rows(0).Cells(3).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim()
GridView1.Rows(0).Cells(4).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim()
结果执行是出错:
"索引超出范围,必须为非负值并小于集合大小,参数明:index"
是不是哪里有错误或者缺少应有的设置,请大家指教。
多谢了!!
GridView1.Rows(0).Cells(0).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim()
GridView1.Rows(0).Cells(1).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim()
GridView1.Rows(0).Cells(2).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim()
GridView1.Rows(0).Cells(3).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim()
GridView1.Rows(0).Cells(4).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim()
结果执行是出错:
"索引超出范围,必须为非负值并小于集合大小,参数明:index"
是不是哪里有错误或者缺少应有的设置,请大家指教。
多谢了!!
确定你有5列吗?
不是(),而是[]。很乱!
ds.Tables(0).Rows(0)(0).Tostring().Trim()
不是(),而是[]
注意列数
还有Cell使用之前也需要new
我的rows(0)已经有了.我也把问题锁定在的cell上
不知道cell怎么new在使用之前!
DataSet DT = mycs.show_all_user();
GridView.PageSize = 8;
GridView.DataSource = DT;
GridView.DataBind();
for (int i = 0;i< DT.Tables[0].Rows.Count; i++)
{
GridView.Rows[i].Cells[4].Text = DT.Tables[0].Rows[i]["real_name"].ToString();
}
==============================================================================
不知道哪里不行!!?????????
{
GridView.Rows[0].Cells[i].Text = DT.Tables[0].Rows[i]["real_name"].ToString();
}