javascript - How do I populate a list box on a textbox change event -
simple one, need please. need populate list box based on values of textbox. sample.aspx code below
<div> <asp:textbox id="textbox1" autopostback="true" runat="server" ontextchanged="textbox1_textchanged"></asp:textbox> <asp:listbox id="listbox1" runat="server"></asp:listbox> </div>
my sample .aspx.cs code below
protected void page_load(object sender, eventargs e) { datalist("page"); } protected void textbox1_textchanged(object sender, eventargs e) { datalist(textbox1.text); } private void datalist(string value) { datatable dt = new datatable(); dt.columns.add("city", typeof(string)); dt.columns.add("country", typeof(string)); (int = 0; < 10; i++) { datarow dr = dt.newrow(); dr["city"] = i.tostring() + value; dr["country"] = i.tostring() + "a"; dt.rows.add(dr); } listbox1.datatextfield = "city"; listbox1.datavaluefield = "country"; listbox1.datasource = dt; listbox1.databind(); }
the textbox1_textchanged fired if control either goes out of focus or hit enter or tab button on textbox. means achieve on fly, eg. key in "b", , should able see listbox reflecting 0b,1b,... 9b. moment add ba, listbox should modify 0ba,1ba,... 9ba.
thanks , regards,
cmr
to call postback without reload page need use updatepanel, if want use asp.net solutions, think these tree post can you.
the ontextchanged fired textbox lose focos or return ir typed
how update textbox onchange without postback?
call text box textchanged event automatically in asp.net
i think do
how make asp.net textbox fire it's ontextchanged event fire in ajax updatepanel?
Comments
Post a Comment