先上代码:
    protected void GridviewData_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Response.write(e.Row.Cells[13].Text);
        }
    }我想输出13列的值,可是加断点此时里的值是空串"",可是GridView绑定呈现在网页上是有数据的,一切正常,我没有使用数据源控件,值接用xxx.DataBind()代码绑定的。后来用for循环把所有的列都输出,可都是""?这是怎么回事?

解决方案 »

  1.   

    应该是获取模板列中控件的值,而不是直接获取cell值
      

  2.   


    Response.write((e.Row.Cells[1].FindControl("模板列的ID") as 模板列的类型).Text);例Response.write((e.Row.Cells[1].FindControl("Lable1") as Lable).Text);
      

  3.   

    Response.write(e.Row[rowIndex].Cells[13].Text);