Try this method.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string script = String.Format("GetdatakeyValue('{0}')", GridView1.DataKeys[e.Row.RowIndex].Value.ToString());
e.Row.Attributes.Add("onclick",script);
}
}
<script language="javascript" type="text/javascript">
function GetdatakeyValue(value)
{
alert (value );
}
</script>