Hi,
I want out put this type
Categories COMPANYNAME
---------- -------------
Categories1 compny1
Categories2 compny2
Categories3 compny3
I done some part of code
now my problem is when type the text in textbox its working when select the Categories or COMPANYNAME using key events its fine but my problem when remove the text in textbox that time the autocomplete is not coming back
means the page is not postbacking this is my proble
i wrote the code in webservice
[System.Web.Services.WebMethod]
public string CheckDateTime(string args)
{
string constructTable="";
int t = args.Length;
if (args == "")
{
int x = 0;
args = x.ToString();
}
int m = 20;
SqlConnection objConnection = new SqlConnection(@"Data Source=STANZOO-FE82BEA\SQLEXPRESS;Initial Catalog=stanzoo;Integrated Security=True");
SqlDataAdapter objdata = new SqlDataAdapter("select distinct categoryid,category from items where category like '" + args + "%'", objConnection);
SqlDataAdapter objdata1 = new SqlDataAdapter("select Top 10 subcategoryid,subcategory from items where subcategory like '" + args + "%'", objConnection);
DataSet objdataset = new DataSet();
DataSet objdataset1 = new DataSet();
objdata.Fill(objdataset, "Categories");
objdata1.Fill(objdataset1, "SubCategories");
constructTable = "<table border='1' cellpadding='5' cellspacing='5' height='150px'>";
constructTable += "<tr><td style='vertical-align:top' class='sdf'>";
constructTable += "<div id='s' style='background-color:red;width:150px;align:center'>Categories</div><div id='san' style='background-color:white;width:150px;align:center'>";
for (int i = 0; i < objdataset.Tables[0].Rows.Count; i++)
{
string s = objdataset.Tables[0].Rows[i]["category"].ToString();
string strText = args.ToLower();
s = s.ToLower();
string x = s.Replace(strText, @"<span style= color:red >" + strText + "</span>");
string after1 = x.Substring(0, 24).ToUpper() + x.Substring(24);
constructTable += "<a style='cursor:pointer'; onclick='javascript:ShowCategory(" + objdataset.Tables[0].Rows[i]["categoryid"].ToString() + ")'><div id='" + i + "' class='cat' onMouseOver=style.backgroundColor='#2172A1'; onMouseOut=style.backgroundColor='#666699';>" + after1 + "</div></a>";
}
constructTable += "</div>";
constructTable += "</td><td style='vertical-align:top'>";
constructTable += "<div style='background-color:red;width:150px;align:center'>CompanyName</div>";
for (int i = 0; i < objdataset1.Tables[0].Rows.Count; i++)
{
string s1 = objdataset1.Tables[0].Rows[i]["subcategory"].ToString();
string strText = args.ToLower();
s1 = s1.ToLower();
string x1 = s1.Replace(strText, "<span style=color:red;>" + strText + "</span>");
string after2 = x1.Substring(0, 24).ToUpper() + x1.Substring(24);
constructTable += "<div id=" + m + " onMouseOver=style.backgroundColor='#2172A1'; onMouseOut=style.backgroundColor='#666699'; style='cursor:Pointer' onclick='javascript:ShowSubcategory(" + objdataset1.Tables[0].Rows[i]["subcategoryid"].ToString() + ")'>" + after2 + "</div>";
m++;
}
constructTable += "</td></tr></table>";
return constructTable;
}
my js file is
var z = null;
var text2 = null;
function ShowText() {
var TextBox = document.getElementById("ctl00_TextBox1");
alert(TextBox.value);
}
$(document).ready(function(e) {
$('#ctl00_TextBox1').keyup(function(e) {
var msgbox = $("#status");
var tx_val = document.getElementById("ctl00_TextBox1").value;
if (e.keyCode != 40 && e.keyCode != 39 && e.keyCode != 38 && e.keyCode != 37) {
$.ajax({
type: "POST",
url: "WebService.asmx/CheckDateTime",
data: "{'args':'" + tx_val + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
msgbox.html(msg.d);
}
});
}
});
});
function ShowCategory(category) {
var id = category - 1;
var str_f = document.getElementById(id).innerHTML;
str_f = str_f.toLowerCase();
str_f2 = str_f.replace(/<span style/g, "");
var str_f3 = str_f2.replace('=', "");
var str_f4 = str_f3.replace('"', "");
str_f4 = str_f4.replace('color', "");
str_f4 = str_f4.replace(':', "");
str_f4 = str_f4.replace('red', "");
str_f4 = str_f4.replace(';', "");
str_f4 = str_f4.replace('"', "");
str_f4 = str_f4.replace('>', "");
str_f4 = str_f4.replace('</span>', "");
str_f4 = str_f4.replace(" ", "");
str_f4 = str_f4.replace(/^\s*|\s*$/g, '');
document.getElementById("ctl00_TextBox1").value = str_f4;
var div = document.getElementById("status");
div.style.display = 'none';
}
function ShowSubcategory(SubCategory) {
$('#ctl00_hdnids').val(SubCategory);
$('#ctl00_btnSubcategory').click();
}
function test(e) {
if (z == null) {
var i = 0;
}
else {
var i = z + 1;
}
var j = 0;
if (e.keyCode == 40) {
if (text2 == null) {
while (document.getElementById("" + j + "")) {
if (i == j) {
document.getElementById("" + j + "").style.background = "#66FF66";
z = i;
document.getElementById("" + j + "").focus();
var str_f = document.getElementById("" + j + "").innerHTML;
str_f = str_f.toLowerCase();
str_f2 = str_f.replace(/<span style/g, "");
var str_f3 = str_f2.replace('=', "");
var str_f4 = str_f3.replace('"', "");
str_f4 = str_f4.replace('color', "");
str_f4 = str_f4.replace(':', "");
str_f4 = str_f4.replace('red', "");
str_f4 = str_f4.replace(';', "");
str_f4 = str_f4.replace('"', "");
str_f4 = str_f4.replace('>', "");
str_f4 = str_f4.replace('</span>', "");
str_f4 = str_f4.replace(" ", "");
document.getElementById('ctl00_TextBox1').value = str_f4;
}
else {
document.getElementById("" + j + "").style.background = "#666699";
}
j++;
}
}
}
else
if (e.keyCode == 38) {
if (text2 == null) {
i = z - 1;
while (document.getElementById("" + j + "")) {
if (i == j) {
document.getElementById("" + j + "").style.background = "#66FF66";
z = i;
document.getElementById("" + j + "").focus();
var str_f = document.getElementById("" + j + "").innerHTML;
str_f = str_f.toLowerCase();
str_f2 = str_f.replace("<span style", "");
var str_f3 = str_f2.replace('=', "");
var str_f4 = str_f3.replace('"', "");
str_f4 = str_f4.replace('color', "");
str_f4 = str_f4.replace(':', "");
str_f4 = str_f4.replace('red', "");
str_f4 = str_f4.replace(';', "");
str_f4 = str_f4.replace('"', "");
str_f4 = str_f4.replace('>', "");
str_f4 = str_f4.replace('</span>', "");
document.getElementById('ctl00_TextBox1').value = str_f4;
}
else {
document.getElementById("" + j + "").style.background = "#666699";
}
j++;
}
}
}
if (e.keyCode == 39) {
document.getElementById('san').style.background = "#666699";
document.getElementById("ctl00_TextBox1").value = "";
if (text2 == null) {
i = z - 1;
while (document.getElementById("" + j + "")) {
if (i == j) {
document.getElementById("" + j + "").style.background = "#FFFFFF";
}
else {
document.getElementById("" + j + "").style.background = "#FFFFFF";
}
j++;
}
var sub = 20;
document.getElementById("" + sub + "").style.background = "#66FF66";
text2 = sub;
document.getElementById("" + sub + "").focus();
var str_f6 = document.getElementById("" + sub + "").innerHTML;
str_f6 = str_f6.toLowerCase();
str_f7 = str_f6.replace("<span style", "");
var str_f8 = str_f7.replace('=', "");
var str_f9 = str_f8.replace('"', "");
str_f9 = str_f9.replace('color', "");
str_f9 = str_f9.replace(':', "");
str_f9 = str_f9.replace('red', "");
str_f9 = str_f9.replace(';', "");
str_f9 = str_f9.replace('"', "");
str_f9 = str_f9.replace('>', "");
str_f9 = str_f9.replace('</span>', "");
document.getElementById("ctl00_TextBox1").value = str_f9;
}
}
else
if (e.keyCode == 40) {
var sub1 = 20;
if (text2 != null) {
sub1 = text2 + 1;
var sub2 = 20;
while (document.getElementById("" + sub2 + "")) {
if (sub1 == sub2) {
document.getElementById("" + sub2 + "").style.background = "#66FF66";
text2 = sub1;
document.getElementById("" + sub2 + "").focus();
var str_f11 = document.getElementById("" + sub2 + "").innerHTML;
str_f11 = str_f11.toLowerCase();
var str_f12 = str_f11.replace("<span style", "");
var str_f13 = str_f12.replace('=', "");
var str_f14 = str_f13.replace('"', "");
str_f14 = str_f14.replace('color', "");
str_f14 = str_f14.replace(':', "");
str_f14 = str_f14.replace('red', "");
str_f14 = str_f14.replace(';', "");
str_f14 = str_f14.replace('"', "");
str_f14 = str_f14.replace('>', "");
str_f14 = str_f14.replace('</span>', "");
document.getElementById("ctl00_TextBox1").value = str_f14;
}
else {
document.getElementById("" + sub2 + "").style.background = "#666699";
}
sub2++;
}
}
}
else
if (e.keyCode == 38) {
if (text2 != null) {
sub1 = text2 - 1;
sub2 = 20;
while (document.getElementById("" + sub2 + "")) {
if (sub1 == sub2) {
document.getElementById("" + sub2 + "").style.background = "#66FF66";
text2 = sub1;
document.getElementById("" + sub2 + "").focus();
var str_f11 = document.getElementById("" + sub2 + "").innerHTML;
str_f11 = str_f11.toLowerCase();
var str_f12 = str_f11.replace("<span style", "");
var str_f13 = str_f12.replace('=', "");
var str_f14 = str_f13.replace('"', "");
str_f14 = str_f14.replace('color', "");
str_f14 = str_f14.replace(':', "");
str_f14 = str_f14.replace('red', "");
str_f14 = str_f14.replace(';', "");
str_f14 = str_f14.replace('"', "");
str_f14 = str_f14.replace('>', "");
str_f14 = str_f14.replace('</span>', "");
document.getElementById("ctl00_TextBox1").value = str_f14;
}
else {
document.getElementById("" + sub2 + "").style.background = "#666699";
}
sub2++;
}
}
}
else
if (e.keyCode == 37) {
document.getElementById("ctl00_TextBox1").value = "";
var f = text2;
text2 = null;
sub2 = 20;
while (document.getElementById("" + sub2 + "")) {
if (sub1 == sub2) {
alert("q");
}
else {
document.getElementById("" + sub2 + "").style.background = "#FFFFFF";
z = -1;
}
sub2++
}
}
if (e.keyCode == 8) {
text2 = null;
z = null;
}
}
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.submit();
}
}
//Javascripts/Jscript.js/
//"AjaxWebServices/NewDealer.asmx/UpsertDealer",</pre>