[英]ASP.NET Code Behind Web Methods
Basically I am trying to filter some results by using web services. 基本上,我试图通过使用Web服务来过滤一些结果。 Here is my HTML code which I added the component dynamically in js file:
这是我在js文件中动态添加组件的HTML代码:
htmlStr += "<div id='filterContent'><input type='checkbox' id='cbShowAllBus' onClick='getAllBusStop();' /><span class='getBusRouteSubtitle'>Show All Bus Stops</span><br/><br/>";
htmlStr += "<span class='getBusRouteTitle'>Bus Services No.</span><br/>";
htmlStr += "<select id='busservice_option' onchange='filterBusStop(this.value);getFilteredBusStop();' style='width:100%;'><option value='default'>Select Bus Service</option><optgroup label='Trunk Bus Services'><option value='2_2'>2</option><option value='3_2'>3</option><option value='4_1'>4</option></optgroup></select>";
htmlStr += "</div><br/>";
I have on checkbox and a drop down list . 我有复选框和一个下拉列表 。 So if checkbox is checked, it will show all the bus stop location without any filter criteria.
因此,如果选中此复选框,它将显示所有公交车站的位置,而没有任何过滤条件。
What I did is from code behind, I call the web service method which execute the SQL statement. 我所做的就是从后面的代码中调用执行SQL语句的Web服务方法。 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.
我不会发布这些功能的代码,因为它可以正常工作。
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:
这是我后面的asp.net代码,用于执行SQL语句并将结果绑定到网格视图:
[System.Web.Services.WebMethod()]
public void filterBusStop(String filter)
{
SgDataService filterBusStop = new SgDataService();
filterBusStopDGV.DataSource = filterBusStop.GetFilterBusStop(filter);
filterBusStopDGV.DataBind();
}
And my web service method which contains the SQL statement: 我的Web服务方法包含SQL语句:
[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);
}
After populate the data into gridview, I loop thru the gridview and plot each results into a map by using lat long: 将数据填充到gridview之后,我遍历gridview并使用lat long将每个结果绘制到地图中:
function getFilteredBusStop() {
var Grid_Table = document.getElementById('filterBusStopDGV');
for (var i = 1; i < 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("<b>Bus Stop Location: </b>" + Grid_Table.rows[i].cells[2].textContent + "<br/>"
+ "<b>Road Name: </b>" + Grid_Table.rows[i].cells[3].textContent + "<br/>"
+ "<b>Buses: </b>" + B1 + "<br/>");
var graphic = PointGraphic;
graphic.setSymbol(symbol);
graphic.setInfoTemplate(infoTemplate);
busIcon.push(map.graphics.add(graphic));
}
}
But somehow, I get an error message which is filterBusStop is undefined
. 但是不知何故,我收到一条错误消息
filterBusStop is undefined
。 I think the problem occurs when onchange at drop down list, I called the code behind web service method in a wrong way. 我认为问题是在下拉列表中的onchange时发生的,我以错误的方式调用了Web服务方法背后的代码。 Any guides?
有指导吗?
Thanks in advance. 提前致谢。 Sorry for the super long thread as I am trying to explain what I am trying to do.
对不起,我正在尝试解释我要做什么,所以超长线程。
i don't know about putting two calls in the onchange event so i'll leave that for now. 我不知道在onchange事件中打两个电话,所以我现在就不讲了。
does the scriptmanager have EnablePageMethods="true"? 脚本管理器是否具有EnablePageMethods =“ true”? if so, try making the method static.
如果是这样,请尝试使该方法静态。 you might have to do both.
您可能必须同时做这两项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.