zoukankan      html  css  js  c++  java
  • Dynamic Picklist Sample

    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    var data = '<?xml version="1.0" encoding="utf-8"?>';
            data = data + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
            data = data + '<soap:Body>';
            data = data + '<GetPicklist xmlns="http://tempuri.org/">';
            data = data + '</GetPicklist>';
            data = data + '</soap:Body>';
            data = data + '</soap:Envelope>';
    var URL="/CustomServices/DynamicPicklist.asmx";

     xmlhttp.open("POST", URL, false);
     xmlhttp.setRequestHeader("Content-Type", "text/xml");
     xmlhttp.setRequestHeader("SOAPAction", "http://tempuri.org/GetPicklist");
     xmlhttp.setRequestHeader("Length",data.length);
     // Send the query.
     xmlhttp.send(data);
     // Get the responses.
     var rx = xmlhttp.ResponseXML;
            var dom=new ActiveXObject("Microsoft.XMLDOM");
            dom.async="false"
            dom.loadXML(rx.text);

    var results = dom.selectNodes("//Table");
    //Loop through the results generating List Item elements.
    var oField=crmForm.all.new_payterm;
    var optiondatas = document.all.new_payterm_d.getElementsByTagName("Option");
    var n_results = results.length;

    for (i=0; i<n_results; i++)
    {

     var Result=results.item(i)
     optiondatas(i+1).text=Result.selectSingleNode("PicklistName").text;
    }
    for (i=n_results; i<=optiondatas.length; i++)
    {
       oField.DeleteOption(i+1);
    }

    C#的代碼部份
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Linq;
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;

    namespace DynamicPicklist.CustomServices
    {
        
    using System.Data.OleDb;
        
    /// <summary>
        
    /// Summary description for DynamicPicklist
        
    /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo 
    = WsiProfiles.BasicProfile1_1)]
        [ToolboxItem(
    false)]
        
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        
    // [System.Web.Script.Services.ScriptService]
        public class DynamicPicklist : System.Web.Services.WebService
        {

            [WebMethod]
            
    public string   GetPicklist(string strCn)
            {
              
        //string strCn = @"Data Source=" + datasource + ";Initial Catalog="+database +";Integrated Security=True";

                  
    // System.Configuration.ConfigurationManager.ConnectionStrings["SQLSeverTest"].ToString ();
                    
                    OleDbConnection cn 
    = new OleDbConnection(strCn);
                    cn.Open();
                    OleDbCommand cmd 
    = new OleDbCommand();
                    cmd.CommandText 
    = "SELECT PicklistId, PicklistName FROM Picklist";
                    cmd.CommandType 
    = CommandType.Text;
                    cmd.Connection 
    = cn;
                    
    //OleDbDataReader reader = cmd.ExecuteReader();

                    
    //System.IO.StringWriter  sw=new System.IO.StringWriter ();
                    OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                    DataSet ds 
    = new DataSet("Picklist");
                    da.Fill(ds);
                    
    return ds.GetXml();
                
                
            }
        }
    }
  • 相关阅读:
    AJAX异步传输——以php文件传输为例
    js控制json生成菜单——自制菜单(一)
    vs2010中关于HTML控件与服务器控件分别和js函数混合使用的问题
    SQL数据库连接到服务器出错——无法连接到XXX
    PHP错误:Namespace declaration statement has to be the very first statement in the script
    【LeetCode】19. Remove Nth Node From End of List
    【LeetCode】14. Longest Common Prefix
    【LeetCode】38. Count and Say
    【LeetCode】242. Valid Anagram
    【LeetCode】387. First Unique Character in a String
  • 原文地址:https://www.cnblogs.com/janmson/p/1388276.html
Copyright © 2011-2022 走看看