title: Gridview fails to rebind data after clicking on a sorted column
body: <p>My application consist of a DropDownList control, which displays a gridview containing the  data related to the name selected from the DropDownList.  I'm attempting to add sorting functionality to to the Grid, but after selecting a name from the DropDownList and the respective data then displayed in the Gridview, I click on a  column name to sort by, but then the gridView goes blank (after clicking the column name).</p>
  
  <p>The HyperText:</p>
  
  <pre><code>&lt;asp:GridView ID="gvShipments" runat="server" Width="718px" EmptyDataText="PO Number Not Found" AutoGenerateColumns ="false" CssClass="Table_default"  AllowSorting="True" OnSorting="gvShipments_Sorting"&gt;
                  &lt;Columns&gt;
                      &lt;asp:BoundField DataField="shipment_guid" HeaderText="Guid" Visible ="false"  /&gt;
                      &lt;asp:BoundField DataField="company_name" HeaderText="Supplier" SortExpression="company_name" /&gt;
                      &lt;asp:HyperLinkField DataTextField ="ponumber" DataNavigateUrlFields ="shipment_guid" DataNavigateUrlFormatString ="~/securepages/shipmentaddedit.aspx?shipment_guid={0}" headertext="PO" SortExpression="ponumber" /&gt;
                      &lt;asp:BoundField DataField="Carrier_Name" HeaderText="Carrier" SortExpression="Carrier_Name" /&gt;
                      &lt;asp:BoundField DataField="TrackingLink" HeaderText="Tracking#" SortExpression="TrackingLink"  /&gt;
                      &lt;asp:BoundField DataField="Plant_Name" HeaderText="Shipped To" SortExpression="Plant_Name"  /&gt;
                  &lt;/Columns&gt;
          &lt;/asp:GridView&gt; 
  </code></pre>
  
  <p>The code behind:</p>
  
  <p><strong>Page Load:</strong></p>
  
  <pre><code> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
              If Not IsPostBack Then
  
              DropDownList1.Items.Insert(0, New ListItem("---Select---", "---Select---"))
              FillDropDownList()
  
              ViewState("SortExpression") = " Shipment_Guid ASC"
              'gvShipments.DataBind()
          End If
      End Sub
  </code></pre>
  
  <p><strong>GridView Sorting Event:</strong></p>
  
  <pre><code>' GridView Sorting Event 
      Protected Sub gvShipments_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
          Dim strSortExpression As String() = ViewState("SortExpression").ToString().Split(" "c)
  
          ' If the sorting column is the same as the previous one, 
          ' then change the sort order.
          If strSortExpression(0) = e.SortExpression Then
              If strSortExpression(1) = "ASC" Then
                  ViewState("SortExpression") = Convert.ToString(e.SortExpression) &amp; " " &amp; "DESC"
              Else
                  ViewState("SortExpression") = Convert.ToString(e.SortExpression) &amp; " " &amp; "ASC"
              End If
          Else
              ' If sorting column is another column,  
              ' then specify the sort order to "Ascending".
              ViewState("SortExpression") = Convert.ToString(e.SortExpression) &amp; " " &amp; "ASC"
          End If
  
          ' Rebind the GridView control to show sorted data.
          gvShipments.DataBind()
      End Sub
  </code></pre>
  
  <p><strong>Shows the data in the Gridview:</strong></p>
  
  <pre><code> Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
          s = WebConfigurationManager.ConnectionStrings("ShipperNotificationConnectionString").ConnectionString
          con = New SqlConnection(s)
          con.Open()
          cmd = New SqlCommand("SELECT Shipment.Shipment_Guid, SupplierCompany.company_name, Shipment_Po.PONumber, Carrier.Carrier_Name, Shipment.TrackingLink, Plant.Plant_Name FROM Plant INNER JOIN Shipment ON Plant.Plant_ID = Shipment.Plant_id INNER JOIN SupplierCompany ON Shipment.Company_Guid = SupplierCompany.Company_guid INNER JOIN Shipment_Po ON Shipment.Shipment_Guid = Shipment_Po.Shipment_guid INNER JOIN Carrier ON Shipment.Carrier_Id = Carrier.Carrier_ID WHERE Plant.Plant_Name ='" + DropDownList1.SelectedItem.ToString() + "'" + "ORDER BY SupplierCompany.company_name ASC ", con)
          dr = cmd.ExecuteReader()
          gvShipments.DataSource = dr
          gvShipments.DataBind()
          dr.Close()
          con.Close()
      End Sub
  </code></pre>
  
  <p>Could I get some help please as to what I'm doing wrong here? Thanks in advance</p>