Click here to Skip to main content
15,886,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i press the link in grid view i want the datakey value of selected row only...
Posted

Try this method.

C#
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);
        }
    }



JavaScript
<script language="javascript" type="text/javascript">
  
    function GetdatakeyValue(value)
    {
        alert (value );
    }
</script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900