Question: Im trying to delete Gridview row on button click. 
i want to save the clicked row's id into a variable. And use this variable in the hyperlink.

here my RowDataBound code

```
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "this.style.cursor='Pointer';this.style.backgroundColor='Yellow'");
       e.Row.RowIndex.ToString())); 

        string id = DataBinder.Eval(e.Row.DataItem, "ProductionOrderId").ToString();
    // somthing like
    // return id ;

    }
}

```

here the hyperlink where i need i id of the selected row

```
<asp:HyperLink  runat="server" NavigateUrl="~/Producter/Delete?id= id" ID="HyperLink1"> Delete</asp:HyperLink>

```

Answer: 
Modified the RowDataBound to hold the GridView record ids to the client side:

```
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "this.style.cursor='Pointer';this.style.backgroundColor='Yellow'");
       e.Row.RowIndex.ToString())); 

        string id = DataBinder.Eval(e.Row.DataItem, "ProductionOrderId").ToString();

        // store the id at the client side
        e.Row.Attributes.Add("id", id);
    }
}

```

And in your javascript code (using jQuery): This will change the hyperlink href value whenever the GridView record would be clicked.

```
<script type="text/javascript">
  $('#<%=GridView1.ClientID %> tr[id]').click(function () {
      idToDelete = $('#<%=GridView1.ClientID %> tr[id]').val();
      $("a.HyperLink1").attr("href", "~/Producter/Delete?id=" + idToDelete);
  });
</script>

```

Although I haven't tested the code, but I hope it should work as required.

**EDIT:**
You should also have added reference for jQuery.js file in the head section like this:

```
<script src="js/jquery-1.6.1.min.js" type="text/javascript"></script>

```
An easier way would be to create a helper method:

```
string getLink(MyObject obj)
{
   return "~/Producter/Delete?id" + obj.ID;
}

```

And in the view:

```
<asp:HyperLink  runat="server" NavigateUrl="<%# getLink(Container.DataItem) %>" ID="HyperLink1"> Delete</asp:HyperLink>

```