Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Gridview在单击已排序的列后无法重新绑定数据_Asp.net_Vb.net_Sorting_Gridview - Fatal编程技术网

Asp.net Gridview在单击已排序的列后无法重新绑定数据

Asp.net Gridview在单击已排序的列后无法重新绑定数据,asp.net,vb.net,sorting,gridview,Asp.net,Vb.net,Sorting,Gridview,我的应用程序由一个DropDownList控件组成,该控件显示一个gridview,其中包含与从DropDownList中选择的名称相关的数据。我试图将排序功能添加到网格中,但在从DropDownList中选择一个名称以及随后在Gridview中显示的相应数据后,我单击要排序的列名,但单击列名后Gridview变为空白 超文本: <asp:GridView ID="gvShipments" runat="server" Width="718px" EmptyDataText="PO Num

我的应用程序由一个DropDownList控件组成,该控件显示一个gridview,其中包含与从DropDownList中选择的名称相关的数据。我试图将排序功能添加到网格中,但在从DropDownList中选择一个名称以及随后在Gridview中显示的相应数据后,我单击要排序的列名,但单击列名后Gridview变为空白

超文本:

<asp:GridView ID="gvShipments" runat="server" Width="718px" EmptyDataText="PO Number Not Found" AutoGenerateColumns ="false" CssClass="Table_default"  AllowSorting="True" OnSorting="gvShipments_Sorting">
                <Columns>
                    <asp:BoundField DataField="shipment_guid" HeaderText="Guid" Visible ="false"  />
                    <asp:BoundField DataField="company_name" HeaderText="Supplier" SortExpression="company_name" />
                    <asp:HyperLinkField DataTextField ="ponumber" DataNavigateUrlFields ="shipment_guid" DataNavigateUrlFormatString ="~/securepages/shipmentaddedit.aspx?shipment_guid={0}" headertext="PO" SortExpression="ponumber" />
                    <asp:BoundField DataField="Carrier_Name" HeaderText="Carrier" SortExpression="Carrier_Name" />
                    <asp:BoundField DataField="TrackingLink" HeaderText="Tracking#" SortExpression="TrackingLink"  />
                    <asp:BoundField DataField="Plant_Name" HeaderText="Shipped To" SortExpression="Plant_Name"  />
                </Columns>
        </asp:GridView> 
GridView排序事件:

显示Gridview中的数据:


我在这里做错了什么,请你帮个忙好吗?提前感谢

我基本上通过使用sqlDataSources并将其绑定到Gridview解决了这个问题

 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
' 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) & " " & "DESC"
            Else
                ViewState("SortExpression") = Convert.ToString(e.SortExpression) & " " & "ASC"
            End If
        Else
            ' If sorting column is another column,  
            ' then specify the sort order to "Ascending".
            ViewState("SortExpression") = Convert.ToString(e.SortExpression) & " " & "ASC"
        End If

        ' Rebind the GridView control to show sorted data.
        gvShipments.DataBind()
    End Sub
 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