Jquery Mobile Select2 with asp.net web service asmx

$("#ddlCust").select2({
minimumInputLength: 2, // minimumInputLength for sending ajax request to server
width: 'resolve', // to adjust proper width of select2 wrapped elements
ajax: {
url: "../DataServices/ws_Master.asmx/GetAutoCompleteCustomerList", // Webservice - WCSelect2 and WebMethod -AccessRemoteData
type: "Post",
dataType: 'json',
params: {
contentType: 'application/json; charset=utf-8'
},
data: function (term) {
return {
term: term,
};
},
processResults: function (data) {
return {
results: data,
more: false
};
}
// error: function (jqXHR, status, error) {
// alert(error + ": " + jqXHR.responseText);
// return { results: [] }; // Return dataset to load after error
//}
}
});

Public Class Customer
Inherits BaseEntity

Private _id As String = String.Empty
Public Property id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property

Private _text As String = String.Empty
Public Property text() As String
Get
Return _text
End Get
Set(ByVal value As String)
_text = value
End Set
End Property

End Class

_
_
Public Sub GetAutoCompleteCustomerList()

Dim sbCustomer As New List(Of Customer)()
Dim strCustCode As String
strCustCode = Me.Context.Request.Params(0)
Try

Using sqlConn As IDbConnection = CreateConnection(cor_DB.clsConStr.SSOConnectionString)
Using sqlCmd As IDbCommand = sqlConn.CreateCommand
sqlCmd.CommandText = "SPP_MST_CUST_AUTOCOMPLETE"
sqlCmd.CommandType = CommandType.StoredProcedure
clsCONN.addInputParam(sqlCmd, "CUST_CODE", strCustCode, clsCONN.dtType.dbString)
clsCONN.addInputParam(sqlCmd, "USER_ID", Portal.PortalSession.UserProfile.User.UserID, clsCONN.dtType.dbString)

Using sqlReader As IDataReader = sqlCmd.ExecuteReader
While sqlReader.Read
Dim st As New Customer()
st.id = sqlReader.GetValue(0) 'id
st.text = sqlReader.GetValue(1)
sbCustomer.Add(st)
End While
End Using
End Using
End Using

Dim result As String = New JavaScriptSerializer().Serialize(sbCustomer)
Me.Context.Response.Write(result)

Catch ex As Exception
Throw (New ExceptionMsg(ex.TargetSite.ReflectedType.Name & "." & ex.TargetSite.Name & " : " & ex.ToString))
End Try

End Sub

Subscribe to Code, Query, Ship, and Learn

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe