I am working on website, I am new to JQuery and Now I am stuck in jquery..
I want to bind all country names in my content page dropdownlist
My Content Page code ,
I removed opening and closing tags as it was not displaying correct in Preview
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server" >
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebForm1.aspx/BindDatatoDropdown",
data: "{}",
dataType: "json",
success: function (data) {
$.each(data.d, function (key, value) {
$("#ddlCountry").append($("<option></option>").val(value.CountryId).html(value.CountryName));
});
},
error: function (result) {
alert('Error');
}
});
});
/script
<asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
<asp:DropDownList ID="ddlCountry" runat="server"></asp:DropDownList>
</div>
</asp:Content>
My Code File
[WebMethod]
public static CountryDetails[] BindDatatoDropdown()
{
DataTable dt = new DataTable();
List<countrydetails> details = new List<countrydetails>();
using (SqlConnection con = new SqlConnection("My Database configuration"))
{
using (SqlCommand cmd = new SqlCommand("SELECT CountryID,CountryName FROM Country", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dtrow in dt.Rows)
{
CountryDetails country = new CountryDetails();
country.CountryId = Convert.ToInt32(dtrow["CountryId"].ToString());
country.CountryName = dtrow["CountryName"].ToString();
details.Add(country);
}
}
}
return details.ToArray();
}
Above Same code I am able to bind data in Normal forms but not in Nested forms (Means inherited from master page) . Please help me