Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have an AutoCompleteExtender from the Ajax Control Toolkit. I need to have a heading in the dropdown list, but it should not be selectable as an item.

I have tried this using jQuery, but even when I just add as a div, it is still selected as an item into the text box when I click on it:

My java script Code is:
XML
<script type="text/javascript">
    // Find the autocompleteextender and set the text as value selected
    function OnItemSelected(event) {
        var selInd = $find("AutoCompleteEx")._selectIndex;
        if (selInd != -1)
            $find("AutoCompleteEx").get_element().value = $find("AutoCompleteEx").get_completionList().childNodes[selInd]._value;

    }

    function OnClientPopulated(sender, eventArgs) {
        //Find the autocompleteextender list
        var autoList = $find("AutoCompleteEx").get_completionList();
        for (i = 0; i < autoList.childNodes.length; i++) {
            // Consider value as image path
            var imgeUrl = autoList.childNodes[i]._value;


            var text = autoList.childNodes[i].firstChild.nodeValue;

            if (text == "header") {
                var newimgeUrl = imgeUrl.split("!");

                autoList.childNodes[i].innerHTML = "<div  style=width:380px;height:30px;background-color:#80BA27;padding:5px;color:black;font-size:16px;text-align:center>Static Heading</div>";

            }
          }
    }
</script>



I also see the same problem at this post:
Show static non-clickable heading in AutoCompleteExtender list[^]

But Unable to solve my problem so plz help me
Posted
Updated 25-Apr-13 1:22am
v6

1 solution

Hi,

can you try like below.
JavaScript
// add the onclick event of the div tag like below in your OnClientPopulated function
if (text == "header") {
    var newimgeUrl = imgeUrl.split("!");
    autoList.childNodes[i].innerHTML = "<div  onclick='return div_click();' style="width:380px;height:30px;background-color:#80BA27;padding:5px;color:black;font-size:16px;text-align:center">Static Heading</div>";

//div_click is onclick event of the div tag
}


javascript function.
JavaScript
function div_click()
{
    document.getElementByID('TextBox1').value = '';  
    //TextBox1 is the Target TextBox Control for AutocompleteExtender.
    // if this inactive item has selected then make the textbox value as empty.
    return false;
}


hope it helps.
 
Share this answer
 
v3
Comments
Arun kumar Gauttam 25-Apr-13 9:39am    
i am try this but it is not work,
thanks for reply
Arun kumar Gauttam 25-Apr-13 15:24pm    
now it will work but i am not fully satisfied with this solution, i think it just jugaad(not proper solution)

But thanks for solution,very good idea
Karthik Harve 25-Apr-13 23:04pm    
Welcome.! Anyway, we will work it out for most desirable solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900