/// <summary> /// GridView控件的翻译,从数据库中取值 /// </summary> /// <param name="dg">要翻译的DataGrid控件</param> /// <param name="columns">二维数组型参数,第二维第一个为字典键值,第二个为默认值</param> public static void TranslationGridViewDB(System.Web.UI.WebControls.GridView gv, string[][] columns) { if (gv.HasControls()) { if (((System.Web.UI.WebControls.GridViewRow)gv.Controls[0].Controls[0]).RowType != System.Web.UI.WebControls.DataControlRowType.EmptyDataRow) { int HeaderIndex = (((System.Web.UI.WebControls.GridViewRow)gv.Controls[0].Controls[0]).RowType == System.Web.UI.WebControls.DataControlRowType.Header) ? 0 : 1; string tlText = string.Empty; for (int i = 0; i < gv.Columns.Count; i++) { tlText = Translate(columns[i][0]); if (tlText == "") { tlText = columns[i][1]; } ((System.Web.UI.WebControls.TableCell)gv.Controls[0].Controls[HeaderIndex].Controls[i]).Text = tlText; } } } }