先在GridView的DataKeyNames屬性中加入你要使用的欄位名稱,例如:DataKeyNames="ID,STUDENT_ID"

接下來在RowDataBound中即可很快的取出你的DataKey的值

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

Response.Write(GridView1.DataKeys[e.Row.RowIndex].Values[0].ToString());
Response.Write(GridView1.DataKeys[e.Row.RowIndex].Values[1].ToString());
}
}

0代表第一個參數,1代表第二個參數

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 法蘭克不要怕 的頭像
    法蘭克不要怕

    法蘭克不要怕

    法蘭克不要怕 發表在 痞客邦 留言(1) 人氣()