public void getAllContent()
    {
        LuckHomeService.Applications[] app = luckHome.GetApplicationType();
        DataTable table = luckHome.GetLuckHomeContent(app[0].CodeName.ToString(), "yinchengliang", UserType.ADGroup.ToString(), DateTime.Now.AddDays(-30), DateTime.Now);
        for (int i = 0; i < table.Rows.Count; i++)
        {
            Label lblWho = (Label)GridView1.Rows[i].FindControl("lblMessageWho");
            Label lblDo = (Label)GridView1.Rows[i].FindControl("lblMessageDo");
            Label lblWhat = (Label)GridView1.Rows[i].FindControl("lblMessageWhat");
            Label lblTime = (Label)GridView1.Rows[i].FindControl("lblMessageTime");
            Label lblBody = (Label)GridView1.Rows[i].FindControl("lblMessageBody");
            lblWho.Text = table.Rows[i]["Sponsor"].ToString();
            lblDo.Text = table.Rows[i]["ShortName"].ToString();
            lblWhat.Text = table.Rows[i]["Title"].ToString();
            lblTime.Text = table.Rows[i]["ActionTime"].ToString();
            lblBody.Text = table.Rows[i]["Description"].ToString();        }
    }
界面就是 
我的GRIDVIEW 里 有 那5个LABEL
-------------
问题就是 
GridView1.Rows[i].FindControl("lblMessageWho");
这句时候就报错 意思就是 girdview 没有ROW[1] 
以前做过 但是现在确实想不来了 希望各位帮下~
项目进行ing..

解决方案 »

  1.   

      你确定了你的那个 table 有值吗?
      

  2.   

    你的label是add到gridview里面的,而不是加到gridview的rows里面的吧
    要用gridview1.findcontrol("")  ?
      

  3.   

    GridView1.Rows[i].Cells[?].FindControl("lblMessageWho"); 
      

  4.   

    是要给GridView的lab赋值,直接在页面Source绑定就可以了text=<%# bind("Sponsor")%>,然后给绑定Datasource就可以了。
    要获取GridView的lable,GridView必须先有行数才可以,你可以先绑定个table让GridView先有行数在进行操作,不过用上面的就好了
      

  5.   

    谢谢你门
    我忘了
    gridview.datasourse=table;
    gridview.databind();
      

  6.   

    GridView1.Rows[i]GV里面没数据,肯定出错咯.
      

  7.   

    你可以加一个判断,这样会避免出错。
    if(GridView1.Rows.count > 0)
    {
     // 你要执行的代码
    }