GridView设置了AllowPaging为False的话,OnRowDataBound中可以用
e.Rows.Cells[2].Text
但如果设置为True后,OnRowDataBound在运行的时候:
异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: index
e.Rows.Cells[2].Text
但如果设置为True后,OnRowDataBound在运行的时候:
异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: index
是以当前一页为单位的,
index是总共的数据行数的话,那当然超出了
比如80行 一页10号
index到10的时候就异常了
foreach (GridViewRow thisItem in GridView1.Rows)
{
}
{
if(e.Row.RowIndex>-1)//需要加上个判断条件
{
string tmp = e.Row.Cells[2].Text;
}
}
两个GridView,导出为Excel表,其一导出结果正常,而另一个得到的Excel表中汉字显示全是乱码?
两个GridView,导出为Excel表,其一导出结果正常,而另一个得到的Excel表中汉字显示全是乱码?====贴出你的导出代码:
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName + ".xls");
ctl.Page.EnableViewState = false;
System.IO.StringWriter wt = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(wt);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(wt.ToString());
HttpContext.Current.Response.End();
}