On head:
<script type = "text/javascript">
function PopulateControl(list, control) {
if (list.length > 0) {
control.removeAttr("disabled");
control.empty().append('<option selected="selected" value="0">Lütfen Seçiniz</option>');
$.each(list, function () {
control.append($("<option></option>").val(this['Value']).html(this['Text']));
});
}
else {
control.empty().append('<option selected="selected" value="0">-<option>');
}
}
var pageUrl = '<%=ResolveUrl("~/pl_yenicarikart.aspx")%>'
function PopulateGrup() {
$("#<%=ddl_grupek.ClientID%>").attr("disabled", "disabled");
console.log($('#<%=ddl_grup.ClientID%>').val());
if ($('#<%=ddl_grup.ClientID%>').val() == "0") {
$('#<%=ddl_grupek.ClientID %>').empty().append('<option selected="selected" value="0">Lütfen Seçiniz</option>');
}
else {
$('#<%=ddl_grupek.ClientID %>').empty().append('<option selected="selected" value="0">Yükleniyor...</option>');
$.ajax({
type: "POST",
url: pageUrl + '/PopulateGrupEk',
data: "{'TXTGRUPKOD':'" + $('#<%=ddl_grup.ClientID%>').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnCountriesPopulated,
failure: function(response) {
alert(response.d);
}
});
}
}
function OnCountriesPopulated(response) {
PopulateControl(response.d, $("#<%=ddl_grupek.ClientID %>"));
}
</script>
----------------HTML
<tr>
<td>Grup</td>
<td>
<asp:DropDownList ID="ddl_grup" runat="server" CssClass="custom-select"
AppendDataBoundItems="true" onchange="PopulateGrup();">
</asp:DropDownList></td>
</tr>
<tr>
<td>Ek Grup</td>
<td>
<asp:DropDownList ID="ddl_grupek" runat="server" CssClass="custom-select">
</asp:DropDownList></td>
</tr>
----------------------------
[System.Web.Services.WebMethod]
public static ArrayList PopulateGrupEk(string TXTGRUPKOD)
{
ArrayList list = new ArrayList();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SBDB"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("select TXTEKGRUPKOD,TXTEKGRUPAD from PanoramaMG where TXTGRUPKOD=@TXTGRUPKOD",con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@TXTGRUPKOD", TXTGRUPKOD);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
list.Add(new ListItem(sdr["TXTEKGRUPAD"].ToString(),sdr["TXTEKGRUPKOD"].ToString()));
}
con.Close();
return list;
}
}
}
in ASP.Net
private void PopulateDropDownList(ArrayList list, DropDownList ddl)
{
ddl.DataSource = list;
ddl.DataTextField = "Text";
ddl.DataValueField = "Value";
ddl.DataBind();
}
}
Source : https://www.aspsnippets.com/Articles/AJAX-Cascading-DropDownList-using-jQuery-in-ASP.Net.aspx