Implementing the server-side method
The server-side method that was specified in the AjaxMethod property
must accept a single string argument and must return a string.
The returned value must be a XML string with the following format:
<combobox>
<container combobox_id="cbo1">
<option value="val1" text="text1" icon="icon1" tooltip="tooltip1" />
<option value="val2" text="text2" icon="icon2" tooltip="tooltip2" />
<option value="val3" text="text3" icon="icon3" tooltip="tooltip3" />
<option value="val4" text="text4" icon="icon4" tooltip="tooltip4" />
<option value="val5" text="text5" icon="icon5" tooltip="tooltip5" />
</container>
</combobox>
The method will load the options from the database and create the XML string.
For example:
public string OnSuggestOptions(string sText)
{
string sResponse = "";
OleDbConnection oConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ Server.MapPath("ABC2.mdb"));
oConn.Open();
string sQuery = "SELECT DISTINCT TOP 10 FirstWord FROM FullTextLookup21 WHERE FirstWord LIKE '"
+ sText.Replace("'", "''") + "%' ORDER BY FirstWord ASC";
OleDbCommand oCommand = new OleDbCommand(sQuery);
oCommand.Connection = oConn;
OleDbDataReader oReader = oCommand.ExecuteReader();
XmlDocument doc = new XmlDocument();
XmlElement tmp;
XmlNode root = doc.CreateNode(XmlNodeType.Element, "combobox", "");
XmlElement container = doc.CreateElement("container");
container.SetAttribute("combobox_id", "cbo1");
while (oReader.Read())
{
tmp = doc.CreateElement("option");
tmp.SetAttribute("value", oReader.GetString(0));
tmp.SetAttribute("text", oReader.GetString(0));
tmp.SetAttribute("icon", "");
tmp.SetAttribute("tooltip", "");
container.AppendChild(tmp);
}
root.AppendChild(container);
doc.AppendChild(root);
sResponse = doc.OuterXml.ToString();
oReader.Close();
oConn.Close();
return sResponse;
}