Input string was not in a correct format
<p>I am using gridview with buttonfield with buttontype image and other fields are IpNo,HospNo,Name,Age</p>

<p>buttonfield will link to another .aspx page when i click this button field it will goes to next page i have no problem in this case </p>

<p>Now i am applied allow sorting property for IpNo,HospNo,Name when i click IpNo it will showing error as Input string was not in a correct format.</p>

<p>my grid view looking as follows</p>

<p>Buttonfield  IpNo   HospNo  Name   Age</p>

<p>for next page i wrote code in rowcommand of gridview</p>

<pre><code>    dim index as Integer = Convert.ToInt32(e.CommandArgument)
    Dim selectedRow As GridViewRow = GridView1.Rows(index)
    Dim ip As String = selectedRow.Cells(1).Text.ToString()

    Dim hospp As String = selectedRow.Cells(2).Text.ToString()
    Dim name As String = selectedRow.Cells(3).Text.ToString()
    Dim psdate As String = selectedRow.Cells(4).Text.ToString()
    Dim pstime As String = selectedRow.Cells(5).Text.ToString()
    Response.Redirect("SurgnIPView.aspx?ip=" &amp; ip)
</code></pre>

<p>for sorting headings i wrote code like this</p>

<p>In pageload i am displaying data to grid from database
        GridView1.DataSource = BindGridView()
        GridView1.DataBind()</p>

<p>for sorting i did as follows
'BindGridView Method fetches data from database and return it as DataTable.</p>

<pre><code>    Private Function BindGridView() As DataTable
    Dim dtGrid As New DataTable()

    If sqlConn.State = ConnectionState.Closed Then
        sqlConn.Open()
    End If

    sqlcomm = "select a.IpNo,a.HospNo,a.PtName,a.Age,a.Ward,a.UnitCode,name1=(select  procName from otprocedures where a.PropSurgcode1=proccode),name2=(select procName from otprocedures where a.PropSurgcode2=proccode),AnsTypeGiven,CONVERT(varchar,a.AllotDate,103) as AllotDate,a.AllotTime,a.AllotORNo,c.DocName from OTScheduleEntry a inner join Doctor c on a.SurgnName=c.DocCode and a.UnitCode=c.Unit where a.OTFlag='No' and a.approval='Yes' and a.SurgnCancelFlag='No'"

    Dim cmd As New SqlCommand(sqlcomm, sqlConn)
    Dim dAdapter As New SqlDataAdapter(cmd)
    dAdapter.Fill(dtGrid)
    Return dtGrid
End Function

    Public Property dir() As SortDirection
    Get
        If ViewState("dirState") Is Nothing Then
            ViewState("dirState") = SortDirection.Ascending
        End If
        Return DirectCast(ViewState("dirState"), SortDirection)
    End Get
    Set(ByVal value As SortDirection)
        ViewState("dirState") = value
    End Set
End Property

   Protected Sub gridview1_Sorting(ByVal sender As Object, ByVal e As  GridViewSortEventArgs)
    Dim sortingDirection As String = String.Empty
    If dir = SortDirection.Ascending Then
        dir = SortDirection.Descending
        sortingDirection = "Desc"
    Else
        dir = SortDirection.Ascending
        sortingDirection = "Asc"
    End If

    Dim sortedView As New DataView(BindGridView())
    sortedView.Sort = Convert.ToString(e.SortExpression) &amp; " " &amp; sortingDirection
    GridView1.DataSource = sortedView
    GridView1.DataBind()
End Sub
</code></pre>

<p>when i click image it will goes to next aspx page bt when i click for IpNo heading for sort it will showing error for  dim index as Integer = Convert.ToInt32(e.CommandArgument)
as Input string was not in a correct format.</p>

<p>Please help this was vry arjent</p>

<p>thank you all</p>
