ASP.net: Changing order of columns in GridView
<p>I have some columns being added to a GridView in codebehind.  In the actual .aspx page I have a link field.  This works fine, but the link field is showing as the first column and I'd prefer it to be shown as the last (all the way to the right).</p>

<p>Is there a way to specify the order so the link field is on the right? I'm using ASP.NET 4.0.</p>

<p>Here's my codebehind:</p>

<pre><code>Private Sub loadDynamicGrid()

    Dim connetionString As String
    Dim connection As SqlConnection
    Dim command As SqlCommand
    Dim adapter As New SqlDataAdapter
    Dim ds As New DataSet
    Dim sql As String

    Dim lastName As String
    Dim linkText As String

    lastName = Request.QueryString("lastName")

    connetionString = ConfigurationManager.ConnectionStrings("dbConnectionString").ConnectionString.ToString()
    sql = "SELECT * FROM [EmployeeList] Where [lastname] like '" &amp; lastName &amp; "%' order by lastname"

    connection = New SqlConnection(connetionString)



    Try
        connection.Open()
        command = New SqlCommand(sql, connection)
        adapter.SelectCommand = command
        adapter.Fill(ds)

        'GridView3.Columns.Clear()

        'Build Bound Columns
        Dim curLastName As New BoundField
        curLastName.HeaderText = "Last Name"
        curLastName.DataField = "LastName"
        GridView3.Columns.Add(curLastName)



        Dim curFirstName As New BoundField
        curFirstName.HeaderText = "First Name"
        curFirstName.DataField = "FirstName"
        GridView3.Columns.Add(curFirstName)


        GridView3.Visible = True
        GridView3.DataSource = ds
        GridView3.DataBind()

        adapter.Dispose()
        command.Dispose()
        connection.Close()



    Catch ex As Exception
        MsgBox("Can not open connection ! ")
    End Try



End Sub
</code></pre>

<p>And here's the GridView code:</p>

<pre><code>&lt;asp:GridView id="GridView3" runat="server" AutoGenerateColumns="False"
EmptyDataText="There are no data records to display."
     AllowPaging="True" 
    CssClass="GridViewStyle" GridLines="None" Width="100%"&gt;
&lt;Columns&gt;


                            &lt;asp:HyperLinkField DataNavigateUrlFields="EmplID"
                                DataNavigateUrlFormatString="EmployeeProfile.aspx?EmplID={0}"
                                DataTextField="EmplID"
                                DataTextFormatString= "&lt;img src='Images/icons/document-search-result.png' alt='View'/&gt; &lt;u&gt;View&lt;/u&gt;" &gt;
                                &lt;ControlStyle CssClass="titleLinksB" /&gt;
                            &lt;ItemStyle Wrap="False" /&gt;
                            &lt;/asp:HyperLinkField&gt;

&lt;/Columns&gt;

&lt;/asp:GridView&gt;
</code></pre>

<p>Thanks for any help!</p>
