Jquery无法在内容页面中工作 [英] Jquery not working in Content Page
本文介绍了Jquery无法在内容页面中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网站上工作,我是JQuery的新手,现在我陷入了jquery ..
我想在我的内容页面下拉列表中绑定所有国家/地区名称
我的内容页面代码,
我删除了开始和结束标签,因为它在预览中显示不正确
< asp:Content ID = Content1 ContentPlaceHolderID = head runat = 服务器 >
< script 类型 = text / javascript >
$(文件).ready(function(){
$ .ajax({
type: POST,
contentType: 应用/ JSON; charset = utf-8,
url: WebForm1.aspx / BindDatatoDropdown,
data: {},
dataType: json,
成功:函数(数据){
$ .each(data .d,function(key, value ){
$( #ddlCountry)。append($( < option>< /选项>)。val( value .CountryId).html( value .CountryName) );
});
},
错误:函数(结果){
alert(' 错误');
}
});
});
/ script
< asp:Content>
< asp:Content ID = Content2 ContentPlaceHolderID = ContentPlaceHolder1 runat = server >
< div>
< asp:DropDownList ID = ddlCountry runat = server > < / asp:DropDownList >
< / div >
< / asp:内容 >
我的代码文件
[WebMethod]
public static CountryDetails [] BindDatatoDropdown()
{
DataTable dt = new DataTable();
列表< countrydetails> details = new 列表< countrydetails>();
使用(SqlConnection con = new SqlConnection( 我的数据库配置))
{
使用(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();
}
上面相同的代码我可以在Normal表单中绑定数据,但不能在嵌套表单中绑定(从master页面继承的Means)。请帮帮我
解决方案
(文件).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 ){
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
解决方案
(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) {
这篇关于Jquery无法在内容页面中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文