in Education by
Basically I recently added a search-box and button to my asp.net site. Issue I'm having now is that even though the searches are clean and things are able to function I am having an issue with sorting both before running any search and afterwards. I feel like I might be missing something after sda(Fill).dt but nothing I've found online seems to help. Doesn't help that its in vb either. Thanks in advance. Imports System Imports System.Configuration Imports System.Data Imports System.Data.SqlClient Imports System.Data.OleDb Imports System.Collections Imports System.Collections.Generic Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports Microsoft.VisualBasic Public Class ShowPOsAdmin Inherits System.Web.UI.Page Dim strConn As String = ConfigurationManager.ConnectionStrings("PurchaseOrderConnectionString").ConnectionString Dim Connection As SqlConnection = New SqlConnection(strConn) Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Me.IsPostBack Then Me.SearchVen() End If End Sub Private Sub SearchVen() Dim Constr As String = ConfigurationManager.ConnectionStrings("PurchaseOrderConnectionString").ConnectionString Using Con As New SqlConnection(Constr) Using cmd As New SqlCommand Dim searchword As String = "SELECT PurchaseOrder.PoId, PurchaseOrder.Vendor_Name, PurchaseOrder.POAmount,PurchaseOrder.DateFrom, PurchaseOrder.DateTo, PurchaseOrder.Balance, PurchaseOrder.CodeId, PurchaseOrder.PoNumber, BPNumber, ClassCode.CodeId AS Expr1, ClassCode.CodeDefinition, PurchaseOrder.Notes FROM PurchaseOrder INNER JOIN ClassCode ON PurchaseOrder.CodeId = ClassCode.CodeId" If Not String.IsNullOrEmpty(TextBox11.Text.Trim()) Then searchword += " Where PurchaseOrder.PONumber Like @POnumber + '%'" cmd.Parameters.AddWithValue("PONumber", TextBox11.Text.Trim()) End If cmd.CommandText = searchword cmd.Connection = Connection Using sda As New SqlDataAdapter(cmd) Dim dt As New DataTable() sda.Fill(dt) dt.DefaultView.Sort = "Vendor_Name ASC" GridView1.DataSourceID = "" GridView1.DataSource = dt GridView1.DataBind() ViewState("dt") = dt End Using End Using End Using End Sub Private Sub DetailsView1_ItemDeleted(sender As Object, e As DetailsViewDeletedEventArgs) Handles DetailsView1.ItemDeleted GridView1.DataBind() Me.SearchVen() End Sub Private Sub DetailsView1_ItemInserted(sender As Object, e As DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted GridView1.DataBind() Me.SearchVen() End Sub Private Sub DetailsView1_ItemUpdated(sender As Object, e As DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated GridView1.DataBind() Me.SearchVen() End Sub Private Sub GridView1_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging GridView1.PageIndex = e.NewPageIndex Me.SearchVen() End Sub Protected Sub TextBox11_TextChanged(sender As Object, e As EventArgs) Handles TextBox11.TextChanged Me.SearchVen() End Sub Protected Sub DetailsView1_PageIndexChanging(sender As Object, e As DetailsViewPageEventArgs) Handles DetailsView1.PageIndexChanging End Sub End Class JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This could help you out. The trick is to never rely on the order of the records within a DataTable. Use a DataView against the DataTable and then bind to the DataView. Imports System.Data.SqlClient Imports System.Data Partial Class PageInitTest Inherits System.Web.UI.Page Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init If Not IsPostBack Then Dim conn As New SqlConnection("myconnectionstring") Dim command As New SqlCommand("mySQL", conn) Dim da As New SqlDataAdapter(command) Dim tblData As New DataTable da.Fill(tblData) ' now the sorting Dim dv As New DataView(tblData) ' you can also do filtering to not show all of them 'dv.RowFilter = "MyField = 1" dv.Sort = "MyField ASC" ' ASC or DESC ' then bind the control to the DataView, not the DataTable dgdMyData.DataSource = dv dgdMyData.DataBind() conn.Close() End If End Sub End Class Example in the link: https://forums.asp.net/t/1063235.aspx?Table+Adapter+problem+with+sort+order

Related questions

0 votes
    I have batch of user accounts and every user account's password is not crypted.I want to insert to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I'm attempting to call my sql stored procedure which takes RaceDate as an input and returns Location as an ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm attempting to call my sql stored procedure which takes RaceDate as an input and returns Location as an ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    So the problem is i don't get get a value from textbox field on GridView RowUpdating event. Here ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    I have been developing a webpage which uses n number of dropdownlists which are binding dynamically inside a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    Which event is fired when Cordova APIs are loaded and ready to use? Please select the correct options from below (a)apiready (b)deviceready (c)appready (d)None of the options...
asked Dec 11, 2020 in Education by Editorial Staff
0 votes
    When is the mouseover event fired? (a) When mouse is moved over a new element (b) When mouse is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    When is the mouseout event fired? (a) When mouse is no longer over an element (b) When mouse is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 22, 2021 in Education by JackTerrance
0 votes
    I am reading through the documentation of UIResponder class and I came across the responder chain. Now it's ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 27, 2022 in Education by JackTerrance
0 votes
    I'm modifying someone else's code where a query is performed using the following: DataSet ds = new ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 23, 2022 in Education by JackTerrance
0 votes
    I want create expression with reflection in c#. I am target script is: using (var service = new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I have a Login control placed inside LoginView control contained within a PANEL. I want to set login button ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    All How can I download a file so the user sees that it is downloading (like with a stream?) I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
...