• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MSCRM janmson
MS CRM顾问及二次开发
博客园    首页    新随笔    联系   管理    订阅  订阅

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();
            
            
        }
    }
}
posted @ 2009-02-11 15:41  韩建兴  阅读(340)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3