You may follow below steps for this.
1) Add a reference of your External JavaScript file in your Aspx Page.
<script type="text/javascript" src="Scripts/MyJavascript.js"></script>
2) Use
Load
or/and
Sorting
Evetnts of your GridView to call your JavaScript function.
http://msdn.microsoft.com/en-us/library/system.web.ui.control.load.aspx
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorting.aspx
3) Call JavaScript function as below.
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "GridLoad", "<script type="text/javascript">Test()</script>");