本文介绍了如何在Jquery中绑定Value的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai我在查询< webmethod>中使用自动填充框_听到我从webmethod获取数据。但我需要如何在文本框中绑定值下面是我的代码



Hai I am using the autocomplete box in query <webmethod> _ hear I am getting the data from webmethod . But i need how to Bind the Value in text box Below is my code

<webmethod()> _
    Public Shared Function GetSelectedValue(ByVal username As String) As String
        Dim result As New List(Of String)()
        Dim strConnString As String = ConfigurationManager.AppSettings("sqlconn").ToString
        Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
        Dim rows As New List(Of Dictionary(Of String, Object))()
        Using con As New SqlConnection(strConnString)
            Using cmd As New SqlCommand("select DISTINCT ItemCode,ItemName,OnHand as 'InStock' from Oitm where ItemName LIKE '%'+@SearchText+'%'", con)
                con.Open()
                cmd.Parameters.AddWithValue("@SearchText", username)
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                Dim oDt As New DataTable
                oDt.Load(dr)

                Dim row As Dictionary(Of String, Object)
                For Each dr1 As DataRow In oDt.Rows
                    row = New Dictionary(Of String, Object)()
                    For Each col As DataColumn In oDt.Columns
                        row.Add(col.ColumnName, dr1(col))
                    Next
                    rows.Add(row)
                Next

            End Using
        End Using
        Return serializer.Serialize(rows)
    End Function




$(document).ready(function () {
            debugger;
            $(".autosuggest").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "Saleorder.aspx/GetAutoCompleteData",
                        data: "{'username':'" + document.getElementById('pagebody_txtSearch').value + "'}",
                        dataType: "json",
                        success: function (data) {
                            debugger
                            response(data.d);
                        },
                        error: function (result) {
                            alert("Error");
                        }
                    });
                },
                select: function (event, ui) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "Saleorder.aspx/GetSelectedValue",
                        data: "{'username':'" + ui.item.value + "'}",
                        dataType: "json",
                        success: function (data) {
                            debugger
                            response(data.d);//hear only i need to bind the Data to textbox ,i am getting the response(data.d)=Object {d: "[{"ItemCode":"P10002","ItemName":"\"PC - P4 2.4G, DDR 1024M, 400G HD\"","InStock":0.000000}]"} like this , But i need to bind the Value of Item Code =txtItemCode Please Help me
                            $("#<%=txtItemCode.ClientID %>").val(data.d.ItemCode)
                        },
                        error: function (result) {
                            alert("Error");
                        }
                    });
                }
            });
        });


推荐答案




这篇关于如何在Jquery中绑定Value的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 05:13