title: ASP.NET Code Behind Web Methods
body: <p>Basically I am trying to filter some results by using web services. Here is my HTML code which I added the component dynamically in js file:</p>
  
  <pre><code>htmlStr += "&lt;div id='filterContent'&gt;&lt;input type='checkbox' id='cbShowAllBus' onClick='getAllBusStop();' /&gt;&lt;span class='getBusRouteSubtitle'&gt;Show All Bus Stops&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;";
  
  htmlStr += "&lt;span class='getBusRouteTitle'&gt;Bus Services No.&lt;/span&gt;&lt;br/&gt;";
  htmlStr += "&lt;select id='busservice_option' onchange='filterBusStop(this.value);getFilteredBusStop();' style='width:100%;'&gt;&lt;option value='default'&gt;Select Bus Service&lt;/option&gt;&lt;optgroup label='Trunk Bus Services'&gt;&lt;option value='2_2'&gt;2&lt;/option&gt;&lt;option value='3_2'&gt;3&lt;/option&gt;&lt;option value='4_1'&gt;4&lt;/option&gt;&lt;/optgroup&gt;&lt;/select&gt;";
  
  htmlStr += "&lt;/div&gt;&lt;br/&gt;";
  </code></pre>
  
  <p>I have on <strong>checkbox and a drop down list</strong>. So if checkbox is checked, it will show all the bus stop location without any filter criteria. </p>
  
  <p>What I did is from code behind, I call the web service method which execute the SQL statement. Then I bind the results into a grid view and extract the results from grid view. I will not post the codes for these functions as it works fine.</p>
  
  <p>My problem occured when I try to filter the results. I used the same technique as above. Here is my asp.net code behind to execute the SQL statement and bind the result to grid view:</p>
  
  <pre><code>[System.Web.Services.WebMethod()]
      public void filterBusStop(String filter)
      {
          SgDataService filterBusStop = new SgDataService();
  
          filterBusStopDGV.DataSource = filterBusStop.GetFilterBusStop(filter);
          filterBusStopDGV.DataBind();
  
      }
  </code></pre>
  
  <p>And my web service method which contains the SQL statement:</p>
  
  <pre><code>[WebMethod]
      public DataSet GetFilterBusStop(String filter)
      {
          SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["EasyMoveConnStr"].ConnectionString);
          string select = "select * from dbo.BusStop where B1 LIKE %" + filter + "%";
          sqlConnection1.Open();
          SqlDataAdapter da = new SqlDataAdapter(select, sqlConnection1);
          DataSet ds = new DataSet();
          da.Fill(ds, "FilterBusStop");
          sqlConnection1.Close();
          return (ds);
      }
  </code></pre>
  
  <p>After populate the data into gridview, I loop thru the gridview and plot each results into a map by using lat long:</p>
  
  <pre><code>function getFilteredBusStop() {
  var Grid_Table = document.getElementById('filterBusStopDGV');
      for (var i = 1; i &lt; Grid_Table.rows.length; i++) {
          var coordXicon = Grid_Table.rows[i].cells[4].textContent;
          var coordYicon = Grid_Table.rows[i].cells[5].textContent;
          var B1 = Grid_Table.rows[i].cells[6].textContent;
          var B2 = Grid_Table.rows[i].cells[7].textContent;
  
          var point = new esri.geometry.Point({ "x": coordXicon, "y": coordYicon, "spatialReference": { "wkid": 3414 } });
          if (B2 == 1) {
              var symbol = new esri.symbol.PictureMarkerSymbol('img/busIcon.png', 30, 30);
          }
          else {
              var symbol = new esri.symbol.PictureMarkerSymbol('img/busstopicon.png', 30, 30);
          }
          var PointGraphic = new esri.Graphic(point, symbol);
          map.graphics.add(PointGraphic);
  
          var infoTemplate = new esri.InfoTemplate();
  
          infoTemplate.setTitle(Grid_Table.rows[i].cells[1].textContent);
  
          infoTemplate.setContent("&lt;b&gt;Bus Stop Location: &lt;/b&gt;" + Grid_Table.rows[i].cells[2].textContent + "&lt;br/&gt;"
          + "&lt;b&gt;Road Name: &lt;/b&gt;" + Grid_Table.rows[i].cells[3].textContent + "&lt;br/&gt;"
          + "&lt;b&gt;Buses: &lt;/b&gt;" + B1 + "&lt;br/&gt;");
  
          var graphic = PointGraphic;
          graphic.setSymbol(symbol);
          graphic.setInfoTemplate(infoTemplate);
          busIcon.push(map.graphics.add(graphic));
      }
  }
  </code></pre>
  
  <p>But somehow, I get an error message which is <code>filterBusStop is undefined</code>. I think the problem occurs when onchange at drop down list, I called the code behind web service method in a wrong way. Any guides?</p>
  
  <p>Thanks in advance. Sorry for the super long thread as I am trying to explain what I am trying to do.</p>