locked
Return value from first Auto Complete list and pass it to second Auto complete list for search RRS feed

  • Question

  • User1480781148 posted

    Hi Friends,

    please help me on following code as I want to get account_no in first search autocompletelist based on return value from first search, I want to get Description in second search. so first search working fine , but second search not return value.

     thank you. regards, asad

    First Search 

    <System.Web.Script.Services.ScriptMethod(), _
    System.Web.Services.WebMethod()> _
    Public Shared Function search_accountno(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
    Dim conn As SqlConnection = New SqlConnection
    conn.ConnectionString = ConfigurationManager _
    .ConnectionStrings("SQLConnection").ConnectionString
    Dim cmd As SqlCommand = New SqlCommand
    cmd.CommandText = "select account_no from coa where" & _
    " account_no like @SearchText + '%'"
    cmd.Parameters.AddWithValue("@SearchText", prefixText)
    cmd.Connection = conn
    conn.Open()
    Dim account_no As List(Of String) = New List(Of String)
    Dim sdr As SqlDataReader = cmd.ExecuteReader
    While sdr.Read
    account_no.Add(sdr("account_no").ToString)
    End While
    conn.Close()
    Return account_no
    End Function

    Second search


    <System.Web.Script.Services.ScriptMethod(), _
    System.Web.Services.WebMethod()> _
    Public Shared Function Searchaccount(ByVal account_no As String, ByVal count As Integer) As List(Of String)
    Dim conn As SqlConnection = New SqlConnection
    conn.ConnectionString = ConfigurationManager _
    .ConnectionStrings("SQLConnection").ConnectionString
    Dim cmd As SqlCommand = New SqlCommand
    cmd.CommandText = "select description from coa where" & _
    " account_no like prefixText + '%'"
    cmd.Parameters.AddWithValue("account_no", account_no)
    cmd.Connection = conn
    conn.Open()
    Dim accno As List(Of String) = New List(Of String)
    Dim sdr As SqlDataReader = cmd.ExecuteReader
    While sdr.Read
    accno.Add(sdr("account_no").ToString)
    End While
    conn.Close()
    Return accno
    End Function

    Monday, September 29, 2014 2:35 AM

Answers

  • User1918509225 posted

    Hi asad_dba,

    I suggest that you can set a breakpoint on the webmethod in the server side. and debug it.

    If you fill data in the table in C#,it is working ,it think it will also work in vb.net.

    For i  am not familiar with vb.net,i suggest that you can use the link below to conver c# to vb.net:

    http://converter.telerik.com/

    Best  Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 30, 2014 1:55 AM

All replies

  • User1480781148 posted

    Hi,

    the following is matching with my requirement , I downloaded the code when I am trying to execute it's not working .  the dropdownlist disable

    http://www.dotnetfox.com/articles/ajax-cascading-dropdown-example-with-database-in-Asp-Net-1078.aspx

    thank you.

    Monday, September 29, 2014 11:08 AM
  • User1480781148 posted

    I converted the c# into vb.net I added webservice.vb as wel downdroplist to default.aspx ,  but still its giving me error [method error 500] please find below my codes

    ---default.aspx 

    <%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="define" EnableEventValidation="true" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

    <asp:DropDownList ID="ddlcountry" runat="server"></asp:DropDownList>
    <cc1:CascadingDropDown ID="CountryCascading" runat="server" Category="Country"
    TargetControlID="ddlCountry" LoadingText="Loading Countries..." PromptText="Select Country"
    ServiceMethod="BindCountry" ServicePath="~/Webservice.asmx">
    </cc1:CascadingDropDown>

    ------webservice.vb 

    Private conn As New SqlConnection(ConfigurationManager.ConnectionStrings("SQLConnection").ConnectionString)
    <WebMethod> _
    Public Function BindCountry(knownCategoryValues As String, category As String) As CascadingDropDownNameValue()
    Dim ds As New DataSet()
    conn.Open()
    Dim cmd As New SqlCommand("select * from Country", conn)
    Dim adp As New SqlDataAdapter(cmd)
    cmd.ExecuteNonQuery()
    adp.Fill(ds)
    conn.Close()
    Dim CountryDetails As New List(Of CascadingDropDownNameValue)()
    For Each DR As DataRow In ds.Tables(0).Rows
    Dim CountryID As String = DR("CountryID").ToString()
    Dim CountryName As String = DR("Country").ToString()
    CountryDetails.Add(New CascadingDropDownNameValue(CountryName, CountryID))
    Next
    Return CountryDetails.ToArray()
    End Function

    Monday, September 29, 2014 1:04 PM
  • User1918509225 posted

    Hi asad_dba,

    I test download the demo which the link provide ,it seems that the demo didn't provide any database for you.

    Please make sure that you have create Country ,State,City tables in the database.

    and make sure you can connect to the database,get the result from the database.

    I suggest that you can set a breakpoint on the web method  in the web service,see if it can be hit and if it has any error message.

    Best Regards,

    Kevin Shen.

    Tuesday, September 30, 2014 12:14 AM
  • User1480781148 posted

    Yes thank you it's working  problem was occurs due to data
    After entering data into tables it's fine
    Please if u check above code in vb having some error
    Thank u
    Regards

    Tuesday, September 30, 2014 12:34 AM
  • User1918509225 posted

    Hi asad_dba,

    I suggest that you can set a breakpoint on the webmethod in the server side. and debug it.

    If you fill data in the table in C#,it is working ,it think it will also work in vb.net.

    For i  am not familiar with vb.net,i suggest that you can use the link below to conver c# to vb.net:

    http://converter.telerik.com/

    Best  Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 30, 2014 1:55 AM