日期:2014-05-17  浏览次数:20440 次

急!!!asp.net后台调用js问题

从数据库里取出数据绑定到gridview后,ButtonField取得ID号,然后再查询数据库,把坐标数据取出来,传到前台js方法,但是不知道怎么触发js事件,ButtonField没有click属性,从后台直接调用js方法也不行,有没有高手指点一下,感激不尽啊!!

前台js方法,
JScript code

function maker(){
     map.clearOverlays(); 
     var x = "<%=longitude%>"; 
     var y = "<%=latitude %>";
     alert(x);
     alert(y);
   var marker = new BMap.Marker(new BMap.Point(x,y)); // 创建标注 
   map.addOverlay(marker); // 将标注添加到地图中
     var infoWindow = new BMap.InfoWindow("欢迎光临"); // 创建信息窗口对象
     marker.addEventListener("click", function(){ this.openInfoWindow(infoWindow);});

}



后台方法
C# code

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "biaozhu")
        {
            sqlid = e.CommandArgument.ToString();//获取id            
        }
        try
        {

            string sql = "select longitude,latitude from SYS_LL where id=" + sqlid;
            DataSet ds = sqlHelper.getDataSet(sql);
            int count = 0;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                Longitudes[count] = System.Double.Parse(dr["Longitude"].ToString());
                longitude += Longitudes[count] ;//将读取的经纬度存储为字符串形式

                Latitudes[count] = System.Double.Parse(dr["Latitude"].ToString());
                latitude += Latitudes[count];//将读取经纬度存储为字符串形式
                count = count + 1;
            }
        }
        catch (Exception ee)
        {
            Response.Write(ee.Message);
        }
        ClientScript.RegisterStartupScript(GetType(), "onclick", "<script>maker();</script>");
    }



------解决方案--------------------
转为模板列就可以了