Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

How to set the value for different controls and I get the value from server-side by ajax

$
0
0

Hi all,

I have built a table as below for test,

Guid    Name

 1         a     

 2         wea

 3         uio

      ...

I want to use the "Name' as the source of AutoComplete( I use JQuery UI to achieve it), actually, I got it. but, when I selected the name to fill the textbox, at the same time, I want to fill the guid of this "Name" to another textbox. I don't know how to achieve my goal.

Hope someone could help me.

Below is my code, but just fot "Name"

<head runat="server"><link href="../Style/jquery-ui.css" rel="stylesheet" /><style type="text/css"></style><title></title><script src="../Scripts/jquery-2.1.4.js"></script><script src="../Scripts/jquery-ui-1.11.4.js"></script><script type="text/javascript">$(function () {$("#tags").autocomplete({
                source: function (request, response) {
                    var param = { cName: $('#tags').val() };$.ajax({
                        url: "WebFormTest16.aspx/GetCompany",
                        data: JSON.stringify(param),
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        dataFilter: function (data) { return data; },
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    value: item
                                }
                            }))
                        }
                    });
                }
            });
        });</script></head><body><form id="form1" runat="server"><div class="ui-widget"><label for="tags">Tags: </label><input id="tags" type="text" /></div></form></body>
[WebMethod]
        public static List<string> GetCompany(string cName)
        {
            List<string> Company = new List<string>();
            string query = string.Format("select Name from AutoComplete WHERE Name LIKE '%{0}%'", cName);
            string connection = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;
            using (SqlConnection con = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand(query, con))
                {
                    con.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Company.Add(reader.GetString(0));
                    }
                }
            }
            return Company;
        }

Above code can work, just for one colum. What I want is get the "Name" 's Guid at the same time.

Plz help me.

Regards,

Swan


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>