Hi, I have listbox wich is dynamically updated with an AJAX call the declaration of the controls
In code behind i'm binding dropdownlist to datasource and adding OnChange Event to make an AJAX call with the function getvalues
protected void Page_Load(object sender, EventArgs e)
{
lb_Retour.DataSource = Ctx.Retours.OrderBy(n => n.Id).Select(n => n);
lb_Retour.DataTextField = "Retour";
lb_Retour.DataValueField = "Id";
lb_Retour.DataBind();
lb_Retour.Items.Insert(0, new ListItem("-Selectionner-", "0"));
lb\_Retour.Attributes\["onchange"\] = "getValues(this);";
}
The javascript wich update the listbox values depending on dropdowlist selection
function getValues(Control) {
var Code = Control.value;
if (Control.value.trim() != "")
$.ajax({
type: "POST",
url: "../Services/DomaineService.asmx/GetResponse",
data: "{ 'typeId': '" + Code + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError
});
}
function OnSuccess(data, status) {
$('#ctl00\_ContentPlaceHolder1\_lb\_Info').children().remove();
$('#ctl00\_ContentPlaceHolder1\_lb\_Info').append(data.d.ValueList);
}
function OnError(request, status, error) {
alert(error.toString());
}
<script></pre>
The data that returns the webservice is
<pre lang="HTML"><option value="1">toto</option><option value="2">titi</option><option value="3">tata</option></pre>
below the Webservice Code
<pre lang="c#">[WebMethod]
public ResponseInfo GetResponse(string typeId)
{
ResponseInfo xResponse = new ResponseInfo();
xResponse.ValueList ="";
PDataContext Ctx = new PDataContext();
var query = (from objInfo in Ctx.Infos
where objInfo.Type == Convert.ToInt32(typeId)
</x-turndown>