how can we handle listbox data on textbox keypress event in asp.net

Posted by Rajasekhar0544 under ASP.NET on 2/5/2014 | Points: 10 | Views : 5343 | Status : [Member] | Replies : 3
Hi,

I have listitems in listbox and need to filtered based on textbox keypress event and has to be displayed in textbox.

Please help me.

Thanks&Regards,
RajSekhar.




Responses

Posted by: Sravan661 on: 2/5/2014 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Please use following code

var txtValue = document.getElementById('<%=TextBox1.ClientID %>').value;
var lstbox = document.getElementById('<%=ListBox1.ClientID %>');
var opt;
var array = new Array();
var array1 = new Array();
array = lstbox.options;
if (txtValue != '') {
for (var i = 0; i < array.length; i++) {
if (array[i].text.toLowerCase().indexOf(txtValue) != -1) {
opt = document.createElement("option");
opt.text = array[i].text;
opt.value = array[i].value;
array1.push(opt);
}
}
lstbox.options.length = 0;
for (var i = 0; i < array1.length; i++) {
opt = document.createElement("option");
opt.text = array1[i].text;
opt.value = array1[i].value;
lstbox.add(opt);
}
}
else {
lstbox.options.length = 0;
for (var i = 0; i < array.length; i++) {
opt = document.createElement("option");
opt.text = array[i].text;
opt.value = array[i].value;
lstbox.add(opt);
}
}
}


fire this function in tetxbox onkeyUp event

sravan

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravan661 on: 2/13/2014 [Member] Bronze | Points: 25

Up
0
Down
Hi,
Does it helped you
revert if you have any queries
else
Mark as ANSWER if satisfied


sravan

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 2/13/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer
http://www.dotnetspark.com/links/4714-filter-listbox-with-textbox.aspx
http://forums.asp.net/t/1325284.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response