protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = FormatDT();
//获取主键指定行
DataRow dr1 = dt.Rows.Find("43100000000000");
for (int i = 0; i < dt.Columns.Count; i++)
{
Response.Write(dr1[i] + "<br/>");
}
object[,] arr = new object[9, 2]
{
{ 0, "身份证号码"}, //数字为列索引
{ 1, "姓名"},
{ 2, "出生年月"},
{ 3, "性别"},
{ 4, "基本工资"},
{ 5, "福利"},
{ 6, "应付合计"},
{ 7, "地址"},
{ 8, "邮政编码"}
};
GridView1.DataSource = dt;
GridView1.DataBind();
//设置GridView列名中文转换
SetGvFieldsCn(arr, dt, GridView1);
}
}
#region 设置GridView中文列名
/// <summary>
/// 设置GridView中文列名
/// </summary>
/// <param name="ObjArr"></param>
/// <param name="dt">DataTable</param>
/// <param name="gv">GridView</param>
protected static void SetGvFieldsCn(object[,] ObjArr,DataTable dt,GridView gv)
{
try
{
for (int i = 0; i < ObjArr.GetLength(0); i++)
{
int j = Convert.ToInt32(ObjArr[i, 0]);
gv.HeaderRow.Cells[j].Text = ObjArr[i, 1].ToString();
}
}
catch (Exception)
{
}
}
#endregion