我的程序:
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"
是不是哪里有错误或者缺少应有的设置,请大家指教。
多谢了!!

解决方案 »

  1.   

    肯定是index超出范围了,行啊列呀,没有那么多,写了那么多
      

  2.   

    GridView1.Rows(0).Cells(4).Text=ds.Tables(0).Rows(0)(0).Tostring().Trim() 
    确定你有5列吗?
      

  3.   

    还有,ds.Tables(0).Rows(0)(0).Tostring().Trim() 
    不是(),而是[]。很乱!
      

  4.   

    GridView1.Rows(0).Cells(4).Text
    ds.Tables(0).Rows(0)(0).Tostring().Trim()  
    不是(),而是[]
    注意列数
      

  5.   

    你确定Rows(0)使用之前已经new了?
    还有Cell使用之前也需要new
      

  6.   

    楼上的兄弟
    我的rows(0)已经有了.我也把问题锁定在的cell上
    不知道cell怎么new在使用之前!
      

  7.   

     代码如下:
      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();
                    
                  }
    ==============================================================================
    不知道哪里不行!!?????????
      

  8.   

    是这样吧  for   (int   i   =   0;i <   DT.Tables[0].Rows.Count;   i++) 
                            { 
                          GridView.Rows[0].Cells[i].Text   =   DT.Tables[0].Rows[i]["real_name"].ToString(); 
                                    
                                }