How Can I (Or Is It Possible?) Add Item to Html Combobox ServerSide ? Or Bind It in behind Code in asp.net ? Does My question Clear?
+2
A:
Do you want to modify a HTML select
tag in code behind?
If yes, here is what you need to do:
- Add
runat=server
in your tag (<select id="s1" runat="server">
) - To bind the control server side, use
a datasource (a datatable for
example), set the datasource
s1.DataSource = dt
set the propertys1.DataTextField
to the property of the datasource you want to bind as the text shown to the user, thes1.ValueTextField
to the property of the datasource to use as the value, and call thes1.Databind()
method - To add/remove items (options) you
can call
s1.Items.Add/AddRange/Insert/Remove/RemoveAt
method.
GôTô
2010-10-18 10:15:07
No i cant add runatserver to my tag because i want to use it with jquery autocomplete http://stackoverflow.com/questions/3948024/bind-asp-net-server-side-data-to-html-combobox
shaahin
2010-10-18 10:45:14
@shaahin: I don't understand, could be more explicit? What is the matter with jquery autocomplete? How exactly do you want databinding to work? Request data from server via jQuery?
GôTô
2010-10-18 12:47:41