代码之家  ›  专栏  ›  技术社区  ›  Community wiki

基于两个参数在文本框中使用上下文键自动完成?

  •  1
  • Community wiki  · 技术社区  · 1 年前

    enter image description here

    参考图片,有2个 TextBox ( tbxAttribute and tbxAttributeDesc )。 在中加载页面时将加载值 tbxAttribute TextBox 在里面 tbxAttributeDesc TextBox 最终用户将填充该数据。

    我已经完成了 Autocomplete Text 在里面 tbxAttributeDesc 。 我们将这些值保存在一个表中,基于加载的 tbxAttribute 相应的价值 AttributeDesc 将突出显示到 tbxAttributeDesc Textbox

    我的代码是:

    autoDesc = new AjaxControlToolkit.AutoCompleteExtender();
    
    autoDesc.ID = "autoDesc" + i; 
    
    autoDesc.BehaviorID = "tbxAtribute" + i;
    
    autoDesc.ServicePath = "itemvaluemas.asmx";
    
    autoDesc.ServiceMethod = "GetAttributeDesc";
    
    autoDesc.TargetControlID = tbxAttributeDesc.ID;
    
    autoDesc.MinimumPrefixLength = 1;
    
    autoDesc.CompletionInterval = 10; 
    
    autoDesc.FirstRowSelected = true;
    
    autoDesc.CompletionSetCount = 30;
    
    autoDesc.UseContextKey = true;
    

    并使用了Javscript概念。

    请参阅下图:

    enter image description here

    这里我需要通过条件作为 tbxAtribute 及其对应 tbxAtributeDesc ,基于此 tbxAbbr 需要突出显示价值。。

    如果我使用 ContextKey 然后我如何在上下文键中传递这两个文本框值。。

    如果你有任何想法,请帮助解决这个问题。

    2 回复  |  直到 12 年前
        1
  •  3
  •   Community Mark    7 年前

    使用ContextKey属性将文本框的值传递给GetAutoCompleteValues函数。

    txtbox1.Attributes.Add("onchange", "$find('BehaviourIDOftbxAttributeDesc').set_contextKey(tbxAttribute.value);");
    

    有关更多信息,请查看以下链接:

    AJAX C# AutoCompleteExtender contextKey

    http://arrao4u.wordpress.com/2010/01/14/autocomplete-extender-with-context-key/

        2
  •  1
  •   Prince Antony G    12 年前

    这就是我找到的解决方案。

    我使用JavaScript:

    function SetContextAbbr(formatid, itemValue, behaveid) {
    var autoComplete1 = $find(behaveid);
    var target = autoComplete1.get_element();
    var txtformatid = document.getElementById(formatid);
    var txtitemValue = document.getElementById(itemValue);
    var contextkeydata = txtformatid.value + "-" + txtitemValue.value;
    autoComplete1.set_contextKey(contextkeydata);
    }
    

    将函数用作

     public string[] GetItemabbr(string prefixText, int count, string contextKey)
     {
            string[] splitvalue = contextKey.Split('-');
    
            //code here
     }
    

    在WebService中

                        autoabbr = new AjaxControlToolkit.AutoCompleteExtender();
                        autoabbr.ID = "autoabbr" + i;
                        autoabbr.BehaviorID = "autoabbrbehave" + i;
                        autoabbr.ServicePath ="itemvaluemas.asmx";
                        autoabbr.ServiceMethod = "GetItemabbr";
                        autoabbr.TargetControlID = txtItemAbbrValue.ID;
                        autoabbr.MinimumPrefixLength = 1;
                        autoabbr.CompletionInterval = 10;
                        autoabbr.FirstRowSelected = true;
                        autoabbr.CompletionListCssClass = "completionList";
                        autoabbr.CompletionListHighlightedItemCssClass = "itemHighlighted";
                        autoabbr.CompletionListItemCssClass = "listItem";
                        autoabbr.CompletionSetCount = 30;
                        autoabbr.UseContextKey = true;