How to pass external values with GridView HyperLinkField which are not part of your Gridview DataSource member ?

Few days back I have published an article “How to pass multiple values using GridView HyperLinkField ?”,  where I have explained how you can pass multiple parameter with Gridview HyperLinkField using DataNavigationUrlField and  DataNavigateUrlFormatString properties. In this post, I am going to explain how you can pass some external values as parameters with the same hyperlink field.

DataNavigationUrlField use only those  fields as parameter which are the part of GridView DataSource. Now the problem comes when you want to pass some other variables as parameter which are not part of the DataSource.  As shown in below image we are passing EmpID and ParentId as argument and this two field are the data member of GridView DataSource.

GridField

Now Say, You want pass ChildID for that particular record along with ParentID and EmpID and you want hyperlink url should be like “Default.aspx?EmpID=1&ParentID=P1&ChildID=C1”where ChildID is not part of datasource.

You can achieve  this by writing code in code behind for the particular GridView. There is two events where you can overwrite the navigation url of that hyperlink field. You can use  Gridview_RowDataBound or Gridview_PreRender for the same.