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..
{
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..
要用gridview1.findcontrol("") ?
要获取GridView的lable,GridView必须先有行数才可以,你可以先绑定个table让GridView先有行数在进行操作,不过用上面的就好了
我忘了
gridview.datasourse=table;
gridview.databind();
if(GridView1.Rows.count > 0)
{
// 你要执行的代码
}