Retrieve the value with `eventArgs.get_value()` function to obtain the selected text instead of the ID

When I populate a textbox with autocomplete using the code below, it only returns the selected text and not the rowid. Any idea why alert(eventArgs.get_value()) doesn't return the actual ID of the row in SQL?

<script language="javascript" type="text/javascript">
    function getSelected(source, eventArgs) {
        alert(eventArgs.get_value())

    }
</script>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    AutoCompleteExtender.OnClientItemSelected = "getSelected"

End Sub

Public Function GetCompletionList(prefixText As String, count As Integer, ByVal contextKey As String) As String[]
    Try
        Dim Con As SqlConnection
        Dim cmd As SqlCommand
        Con = New SqlConnection
        Dim test As String
        test = contextKey
        Con.ConnectionString = ""
        Con.Open()

        cmd = New SqlCommand
        cmd.Connection = Con
        'cmd.CommandText = "SELECT NPI, [Entity Type Code], [Provider Last Name (Legal Name)], [Provider First Name], [Provider Business Mailing Address City Name] FROM NPIData WHERE [Provider Last Name (Legal Name)] LIKE @Provider + '%' AND [Provider Business Mailing Address City Name] = @State"
        cmd.CommandText = "SELECT NPI, [Entity Type Code], [Provider Last Name (Legal Name)], [Provider First Name], [Provider Business Mailing Address City Name], [Provider Business Mailing Address State Name], [Provider Business Mailing Address Postal Code] FROM NPIData WHERE     ([Provider Business Mailing Address State Name] = @State) AND ([Provider Last Name (Legal Name)] LIKE N'%' + @Provider + N'%') ORDER BY [Provider First Name]"
        cmd.Parameters.AddWithValue("@Provider", prefixText)
        cmd.Parameters.AddWithValue("@State", contextKey)
        Dim customers As List(Of String) = New List(Of String)
        Dim reader As SqlDataReader = cmd.ExecuteReader()


        While reader.Read
            customers.Add(reader("Provider Last Name (Legal Name)").ToString + ", " + reader("Provider First Name").ToString + "          " + reader("Provider Business Mailing Address City Name").ToString + ", " + reader("Provider Business Mailing Address State Name").ToString + "  " + reader("Provider Business Mailing Address Postal Code").ToString)

        End While


        Con.Close()

        Return customers.ToArray
    Catch ex As Exception

    End Try

Answer №1

The reason why the row ID is not being returned is because you have not properly populated it in the AutoExtender. You have only assigned a text value to it without an underlying value. To populate the customers, you need to follow this format (assuming NPI is your row ID):

customers.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(
reader("NPI").ToString,
reader("Provider Last Name (Legal Name)").ToString + ", "
 + reader("Provider First Name").ToString + "          " + reader("Provider Business Mailing Address City Name").ToString + ", " 
+ reader("Provider Business Mailing Address State Name").ToString + "  " + reader("Provider Business Mailing Address Postal Code").ToString))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you outline the key distinctions between AngularJS and ReactJS?

Looking to create a website that will be converted into a mobile application, I realize that my expertise lies more in desktop and Android native development rather than web client side development. After some research, I have decided to utilize HTML5, CSS ...

Animating with JQuery utilizing a dynamic attribute

We are facing a challenge with animating multiple divs that share the same class name and have different attribute values: <div class="chart-bar" style="width:10%;" bar-width="100%"></div> <div class="chart-bar" style="width:10%;" bar-wid ...

What is the process for adjusting the position following the modification of a table value in React?

In my React UI, I have set up two text fields for entering values. After saving the values, they are displayed in a table below (designed with antd). When I click on a record in the table to edit it, I want the data from that record to populate the text f ...

Can side effects be safely incorporated within the callback of the useState hook?

Consider this scenario: const [value, setValue] = useState(false); const setSomething = (val) => { setValue((prev) => { fn(); dispatch(action); // or any other side effect return prev + val; }); }; Is it acceptable and in line with ...

Performing an AJAX Post request with Jquery in a Ruby on Rails web

Using a straightforward controller setup: def new @product = Product.new respond_to do |format| format.html #new.html.erb format.json { render json: @product} end end def create @product = Product.new(params[:product]) ...

Restricting the selection of years in the Ajax Toolkit calendar extender

I am trying to use the Ajax toolkit calendar extender control, with the goal of restricting the year selection to a range from 1900 to the current year. I found a solution mentioned here which suggests using StartDate and EndDate properties. However, when ...

ControlsContainer - jQuery object for Flexslider

I recently tried to implement a flexslider with controls in a separate div using the controlsContainer option provided by flexslider. The setup consists of a left column containing the slider code (".flexslider-small"), a right column with text, and the c ...

The conflict between Material UI's CSSBaseline and react-mentions is causing issues

Wondering why the CSSBaseline of Material UI is causing issues with the background color alignment of React-mentions and seeking a solution (https://www.npmjs.com/package/react-mentions) Check out this setup: https://codesandbox.io/s/frosty-wildflower-21w ...

Displaying WordPress plugin queries in a linked file

I have been working on developing a custom WordPress plugin that involves querying a database based on user input and then displaying the results in an HTML file with links. While I have managed to successfully display the HTML page, I am facing an issue w ...

React is unable to locate the component element within the DOM

I'm attempting to set the innerHTML for the div element with the ID of ed. Unfortunately, I am unable to access it once React has finished rendering. It seems that this is due to the render stages, as I am receiving a null value for the div element. W ...

Struggling to implement a Datepicker in the date column of a table created using HTML and JavaScript

I am encountering an issue while creating a table in html and javascript. I am unable to use a Datepicker in the date column when inserting a new row, even though it works fine when using in normal html code. Below is the javascript function: //Script fo ...

Only implement $(document).on(...) for every JQuery request

As someone new to Jquery, I'm facing challenges in grasping its functionality. Specifically, my struggle lies in setting up an event listener on an i element with the class of .dataPickerIcon, which should respond to a click by inserting more HTML usi ...

Steps for retrieving information from a View, transferring it to a Controller, and subsequently forwarding it to another View

Hello everyone! So, I have a situation where I need to pass values from a view using @Html.ActionLink to a controller and then pass them to a new view. I've tried creating a ViewModel that matches the values I need, but when I try to show these result ...

How can these lines be drawn in a simple manner?

I have been using the div tag to create a line, but I'm looking for an easier solution. If you have another method in mind, please share it with me. #line{ background-color:black; height:1px; width:50px; margin-top:50px; margin-left:50px; f ...

Utilizing React Router to dynamically render components based on JSON object data

My current challenge involves rendering React components based on the component names in a JSON file I've created. Specifically, I want to render the TestSection component within the context of my Route component. To achieve this, I am utilizing the ...

Exploring dynamic content with AngularJS: Navigating through AJAX-driven

After researching various articles on how to crawl ajax sites, I came across a document stating that in order to make ajax sites crawlable, we need to provide an HTML snapshot of the page. As I am utilizing Ruby On Rails as my server-side language, this in ...

Roundabout Navigation Styles with CSS and jQuery

My goal is to implement a corner circle menu, similar to the one shown in the image below: https://i.stack.imgur.com/zma5U.png This is what I have accomplished so far: $(".menu").click(function(){ $(".menu-items").fadeToggle(); }); html,body{ colo ...

What is the reason for the return of undefined with getElementsByClassName() in puppeteer?

Currently, I am utilizing puppeteer to fetch certain elements from a webpage, specifically class items (divs). Although I understand that getElementsByClassName returns a list that needs to be looped through, the function always returns undefined for me, e ...

Cannot retrieve the <li> element from the array

I am trying to display list items inside an ordered list (ul) from an array, but I am facing issues with it. Whenever I try to map through the array, I encounter an error message saying Map is not a function. Any assistance on resolving this would be hig ...

Create a script that ensures my website can be set as the homepage on any internet browser

I am currently in search of a way to prompt users on my website to set it as their homepage. Upon clicking "Yes," I would like to execute a script that will automatically make my website the user's browser homepage. I have come across a Similar Thread ...