Hi,
i am searchin for a Solution which make it possible to show more than one colum with the AutoCompleteExtender.
The reason is that i use the Control for a search. The user has to type the name of a City. The problem is, that the cityname is´nt unique, so i have to give the user more informations to the Results.
Example:
The User types
"bergen"
for "bergen" in the Database are 3 entries which have a different Postcode
So the dropdownlist show three times "bergen"
When the dropdownlist could show this "bergen 12345" next line "bergen 54789" and so on, this would be perfekt.
I have found an Example in which someone has changed the result value from the webservice from a Stringarray to XmlDocument. So he has changed the AutoCompleteBehavior.js and the ServiceMethod.
The resultlist is shown in a Table. This works fine with the Release of the AjaxControlToolKit. But in the Release, there are problems with scrollbars which were shown when the Resultlist is to long, and they have to be show because i didn´t limit the resultlist.
So i downloaded the latest Version and i have tried the code to adapt.
Here is the code where the table for the Resultlist is created.
_update: function(prefixText, completionItems, cacheResults) {
/// <summary>
/// Method to update the status of the autocomplete behavior
/// </summary>
/// <param name="prefixText" type="String" DomElement="false" mayBeNull="true" />
/// <param name="completionItems" type="Object" DomElement="false" mayBeNull="true" />
/// <param name="cacheResults" type="Object" DomElement="false" mayBeNull="true" />
/// <returns />
if (cacheResults && this.get_enableCaching()) {
if (!this._cache) {
this._cache = {};
}
this._cache[prefixText] = completionItems;
}
doc = completionItems.documentElement;
var items = completionItems.getElementsByTagName('ROW');
this._completionListElement.innerHTML = '';
this._selectIndex = -1;
var _firstChild = null;
if (completionItems && completionItems.length) {
var newtable = document.createElement("TABLE");
newtable.width='100%';
var newtbody = document.createElement("TBODY");
newtable.appendChild(newtbody);
for (var i = 0; i < completionItems.length; i++) {
//if (this._completionListElementID) {
// // the completion element has been created by the user and li won't necessarily work
// var itemElement = document.createElement('div');
//} else {
// var itemElement = document.createElement('li');
//}
var newtr = document.createElement("TR");
for ( var j=items[i].firstChild ; j!=null ; j=j.nextSibling ){
// create column
var newtd = document.createElement("TD");
var itemdata;
if ( document.all )
itemdata = j.text;
else
itemdata = j.textContent;
if ( j.nodeName == this._returnColumn )
newtr.title = itemdata;
if ( j.nodeName == "ROWINDEX" )
continue;
newtd.appendChild(document.createTextNode(this._getTextWithInsertedWord(itemdata)));
newtr.appendChild(newtd);
}
newtbody.appendChild(newtr);
// set the first child if it is null
if( _firstChild == null ){
_firstChild = newtr;
}
if (this._completionListItemCssClass) {
Sys.UI.DomElement.addCssClass(newtr, this._completionListItemCssClass);
} else {
var itemElementStyle = newtr.style;
itemElementStyle.padding = '1px';
itemElementStyle.textAlign = 'left';
itemElementStyle.textOverflow = 'ellipsis';
itemElementStyle.backgroundColor = this._textBackground;
itemElementStyle.color = this._textColor;
}
}
this._completionListElement.appendChild(newtable);
//var elementBounds = CommonToolkitScripts.getBounds(this.get_element());
//this._completionListElement.style.width = Math.max(1, elementBounds.width - 2) + 'px';
this._completionListElement.scrollTop = 0;
this.raisePopulated(Sys.EventArgs.Empty);
var eventArgs = new Sys.CancelEventArgs();
this.raiseShowing(eventArgs);
if (!eventArgs.get_cancel()) {
this.showPopup();
// Check if the first Row is to be selected by default and if yes highlight it and updated selectIndex.
if (this._firstRowSelected && (_firstChild != null)) {
this._highlightItem( _firstChild );
this._selectIndex = 0;
}
}
} else {
this._hideCompletionList();
}
}
}
Edit:
Propertys of the Control on the Webpage:
<div id="listPlacement" style="height: 100px; width: 300px; overflow-y:scroll" >
</div>
<ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server" CompletionInterval="500"
CompletionListElementID="listPlacement" CompletionSetCount="20" EnableCaching="true"
MinimumPrefixLength="2" ServiceMethod="GetCompletionList" ReturnColum="Ort"
ServicePath="AutoComplete.asmx" TargetControlID="TextBox1"></ajaxToolkit:AutoCompleteExtender>
I can´t post the whole code because it is to long. But you can download it from http://download.hpinfomedia.de/Ajax/AutoCompleteBehavior.js
With this Code noting happend when the user types anything.
I don´t know how debug the Code and i am not sure that i can this because i use only the Visual Web Developer and for creating the new dll i use SharpDevelop 2.1
I hope someone can help me.
Thanks
Christian