I would like to have the code to set focus in a textbox within a datagrid on the click of a button which is outside the datagrid. I have written a code which does not work. Please give me the solution.

The following is the error which occurs.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. The error is on the following line
Txtfocus = CType(GrdDailyDropout.FindControl("TxtSlip_No"),Textbox).Text


Public Sub Display(S as Object, E as EventArgs)

Dim Gritem as DataGridItem
Dim Txtfocus as String

If CheckValidity = True Then

Call DisplayRecordMatch()
Call Fill_Grid()

For each Gritem in GrdDailyDropout.Items
Txtfocus = CType(GrdDailyDropout.FindControl("TxtSlip_No"),Textbox).Text
Response.write(Txtfocus & "<br>")

Next



'Dim scriptString as String = "<script language=JavaScript>"
' scriptString += "" & Txtfocus.ClientID & ".focus();<"
' scriptString += "/"
' scriptString += "script>"
' RegisterStartupScript ("clientScript", scriptString)

End if

End Sub