how to call query from web service..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ieda
    New Member
    • Mar 2010
    • 4

    #1

    how to call query from web service..

    Hello,

    I using ajax autocomplete in gridview to select the data. Once i select the data from textbox gridview i want the other textbox in gridview display related data. i use a javascript and put it in markup to call the webservice query and ajax autocomplete in app code. The problem is when i select the data using ajax the data from other textbox not display..

    Here is an example...

    This coding ajax to select the data from gridview textbox name task_person:-


    Code:
     if (field_txtbox.ID == "task_person")
                        {
                            AjaxControlToolkit.TextBoxWatermarkExtender twe = new AjaxControlToolkit.TextBoxWatermarkExtender();
                            twe.ID = "twe" + field_txtbox.ID;
                            twe.TargetControlID = field_txtbox.ID;
                            twe.WatermarkText = "person";
                            Container.Controls.Add(twe);
                            AjaxControlToolkit.AutoCompleteExtender autosuggest = new AjaxControlToolkit.AutoCompleteExtender();
                            autosuggest.ID = "autoSuggest" + field_txtbox.ID;
                            autosuggest.ServiceMethod = "GetMember";     
                            autosuggest.TargetControlID = field_txtbox.ID;
                            autosuggest.CompletionSetCount = 50;
                            autosuggest.EnableCaching = true;
                            autosuggest.MinimumPrefixLength = 3;
    
                            autosuggest.OnClientItemSelected = "test";
                           
                            Container.Controls.Add(autosuggest);
                           
                        }


    This coding in web service:-

    Code:
    <WebMethod()> _
       <Script.Services.ScriptMethod()> _
       Public Shared Function GetDept(ByVal prefixText As String, ByVal count As Integer) As System.String()
    
            Dim iCount As Integer
    
            iCount = 10
    
            Dim items As New List(Of String)(count)
            Dim ds As New DataSet()
            Dim connectionString As String = "Data Source=202.75.36.58;Initial Catalog=PGB_POD_IMS;Persist Security Info=True;User ID=pgbuser;Password=p@ssw0rd"
            Using connection As New SqlConnection(connectionString)
                Dim sql As String = "SELECT user_department FROM m_user WHERE user_fullnm LIKE '%" + prefixText + "%'"
                Dim adapter As New SqlDataAdapter()
                adapter.SelectCommand = New SqlCommand(sql, connection)
                adapter.Fill(ds)
            End Using
            For Each dr As DataRow In ds.Tables(0).Rows
                items.Add(dr("user_department").ToString())
    
            Next
            Return items.ToArray()
    
        End Function


    This is javascript function:-



    Code:
    function test()
        {
         document.getElementById('TableGridView_ctl06_task_department').value='result';
        }



    I just use the word result to pass value to ensure the function can pass the data or not. I don't know how can i use the java script function to call the web service query. Please anybody correct my code..
    Last edited by Dormilich; Mar 31 '10, 06:30 AM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    read about AJAX, that’s used for JavaScript <=> server communication

    Comment

    Working...