Wednesday, April 15, 2009

How to populate ListBox and DropDownList data with javascript

<strong>
< script type="text/javascript" >

function add()
{

AddListBox("sai","1");
AddListBox("sai2","2");
AddListBox("sai3","3");

}
function AddListBox(Text,Value)
{
var opt = document.createElement("option");
document.getElementById('<% =ListBox1.ClientID%>').options.add(opt);
opt.text = Text;
opt.value = Value;
}

</ script >

< body onLoad="add()">
<form id="form1" runat="server">
< div>

<asp:ListBox ID="ListBox1" runat="server" ></asp:ListBox>

</div>
</form>
</body>
</html>
</strong>

No comments: