自动完成扩展程序-不允许选择特定项目 [英] autocomplete extender--Not allowed to select a particular item

查看:62
本文介绍了自动完成扩展程序-不允许选择特定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自动填充扩展程序,可以显示活动和非活动项目.
但是我不允许用户选择非活动项目.
我可以通过以下代码更改禁用某项的功能,但无法阻止选择处于非活动状态的项.
请帮帮我

I have an autocomplete extender, which shows both active and Inactive items.
But I''m not allowing the user to select an Inactive item.
I can change disable an item by the below code, but not able to stop an Inactive item from being selected.
Please help me

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<script type="text/javascript" language="javascript" >


 function fnFormatTeamProfDetails()
    {

       var comletionList = $find("AutoProfTeam").get_completionList();
      for (i = 0; i < comletionList.children.length; i++) {

       comletionList.children[i].innerHTML = fnGetFormattedItem(comletionList.children[i].innerHTML);

       }

    }



    function fnGetFormattedItem(itemToFormat)

    {

         // debugger;;

            var itemHTML = "";



                        itemHTML = '<table border="0" cellspacing="0" width="370px" >'



                        //Determine Row Style : Active or Inactive

                        if (itemToFormat == 'Inactive') {

                            itemStyle = 'style="background-color:Gray;"';

                            //itemStyle = '';

                            inActiveTxtStyle = 'style="vertical-align:top;color:Red;width:15%;"'

                            //font-weight:bold

                        }

                        else {

                            itemStyle = '';

                            inActiveTxtStyle = 'style="vertical-align:top;width:15%;"'

                        }



                        //Add the First Column: Name

                        if (itemStyle == 'style="background-color:Gray;"')

                        {

                        itemHTML = itemHTML + '<tr disabled  id="trdisabled"  ' + itemStyle + '<td style="vertical-align:top;width:20%;" _value="' + itemToFormat+ '">'+ itemToFormat + '</td>';
                        }
                        else
                        {
                        itemHTML = itemHTML + '<tr' + itemStyle + '<td style="vertical-align:top;width:20%;" _value="' + itemToFormat + '">' + itemToFormat + '</td>';
                        }

                       itemHTML = itemHTML + '</tr></table>';
               return itemHTML;
     }
     function fun()
     {
     alert("Hi");
      return false;
     }


</script>

    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    <div>
    <asp:TextBox runat="server" Style="width: 220px" ID="TextBox1"></asp:TextBox>
    <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"

                            ServiceMethod="GetCountryInfo" BehaviorID="AutoProfTeam" MinimumPrefixLength="1" OnClientPopulated="fnFormatTeamProfDetails" OnClientItemSelected="fun" >
     </cc1:AutoCompleteExtender>

    </div>
    </form>
</body>
</html>





[System.Web.Services.WebMethod()]
      [System.Web.Script.Services.ScriptMethod()]
      public static string[] GetCountryInfo(string prefixText,int count)
      {
          string[] items = { "Active","Inactive"};
          return items;
      }

推荐答案

find("AutoProfTeam").get_completionList(); 对于(i = 0; i < compleionList.children .length; i ++) { span> compleionList.children [i] .innerHTML = fnGetFormattedItem(comletionList.children [i] .innerHTML); } } 功能 fnGetFormattedItem (itemToFormat) { // 调试器;; itemHTML =" " itemHTML <表格边框=" 0"cellspacing =" 0"width =" 370px>' //确定 : 有效 无效 如果 ( itemToFormat = = 无效") { itemStyle =' style ="background-color:Gray;"' ; //itemStyle =' ' ; inActiveTxtStyle =' style ="vertical-align:top; color:Red; width:15%;"' //font-weight:bold } 其他 { itemStyle =' ' ; inActiveTxtStyle =' style ="vertical-align:top; width:15%;"' } //添加 列: 名称 span> if ( itemStyle == 'style="background-color:Gray;"') { itemHTML = itemHTML + '<tr disabled id="trdisabled" ' + itemStyle + '<td style="vertical-align:top;width:20%;" _value="' + itemToFormat+ '">'+ itemToFormat + '</td>'; } 别的 { itemHTML = itemHTML + '<tr' + itemStyle + '<td style="vertical-align:top;width:20%;" _value="' + itemToFormat + '">' + itemToFormat + '</td>'; } itemHTML = itemHTML + '</tr></table>'; return itemHTML; } function fun() { alert("Hi"); 返回false; } < /script > < 标题 > 无标题页面< /title > < /head > < 正文 > < 表单 =" form1" runat >服务器" > <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> < /asp:ScriptManager > < div > <asp:TextBox runat="server" Style="width: 220px" ID="TextBox1"></asp:TextBox> <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCountryInfo" BehaviorID="AutoProfTeam" MinimumPrefixLength="1" OnClientPopulated="fnFormatTeamProfDetails" OnClientItemSelected="fun" > < /cc1:AutoCompleteExtender > < /div > < /form > < /body > < /html >
find("AutoProfTeam").get_completionList(); for (i = 0; i < comletionList.children.length; i++) { comletionList.children[i].innerHTML = fnGetFormattedItem(comletionList.children[i].innerHTML); } } function fnGetFormattedItem(itemToFormat) { // debugger;; var itemHTML = ""; itemHTML = '<table border="0" cellspacing="0" width="370px" >' //Determine Row Style : Active or Inactive if (itemToFormat == 'Inactive') { itemStyle = 'style="background-color:Gray;"'; //itemStyle = ''; inActiveTxtStyle = 'style="vertical-align:top;color:Red;width:15%;"' //font-weight:bold } else { itemStyle = ''; inActiveTxtStyle = 'style="vertical-align:top;width:15%;"' } //Add the First Column: Name if (itemStyle == 'style="background-color:Gray;"') { itemHTML = itemHTML + '<tr disabled id="trdisabled" ' + itemStyle + '<td style="vertical-align:top;width:20%;" _value="' + itemToFormat+ '">'+ itemToFormat + '</td>'; } else { itemHTML = itemHTML + '<tr' + itemStyle + '<td style="vertical-align:top;width:20%;" _value="' + itemToFormat + '">' + itemToFormat + '</td>'; } itemHTML = itemHTML + '</tr></table>'; return itemHTML; } function fun() { alert("Hi"); return false; } </script> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> </asp:ScriptManager> <div> <asp:TextBox runat="server" Style="width: 220px" ID="TextBox1"></asp:TextBox> <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCountryInfo" BehaviorID="AutoProfTeam" MinimumPrefixLength="1" OnClientPopulated="fnFormatTeamProfDetails" OnClientItemSelected="fun" > </cc1:AutoCompleteExtender> </div> </form> </body> </html>





[System.Web.Services.WebMethod()]
      [System.Web.Script.Services.ScriptMethod()]
      public static string[] GetCountryInfo(string prefixText,int count)
      {
          string[] items = { "Active","Inactive"};
          return items;
      }


Difink, in CP I added on technical blog entry about
Ajax AutoComplete in ASP.NET[^] without using native controls in VS. It will help you to solve this issue. you can customize my handler file code like

Difink, in CP I added on technical blog entry about
Ajax AutoComplete in ASP.NET[^] without using native controls in VS. It will help you to solve this issue. you can customize my handler file code like

table = "<table width='100%'>";
            string td = string.Empty;
            //checking datatable
                if (dataTable.Rows.Count > 0)
                {
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
if(active)
{
                        //adding table rows
                        td += string.Format("<tr><td class='select'
            onclick='api_helper.AddtoTaxtBox(this.innerHTML)'>
            {0}</td></tr>", dataTable.Rows[i][0].ToString());
}
else
{
//remove the selection javascript code
//then put add td values
}
                    }
                }
                table += td + "</table>";
                context.Response.Write(table);


Could you please provide the javascript code for remove the selection from autocomplete extender javascript code
Could you please provide the javascript code for remove the selection from autocomplete extender javascript code


这篇关于自动完成扩展程序-不允许选择特定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆