当我使用以下Java脚本时,编辑在网格中不起作用 [英] Edit Is Not Working In Grid When I Use My Following Java Script

查看:67
本文介绍了当我使用以下Java脚本时,编辑在网格中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑在网格中不起作用,没有这个javascript代码编辑工作





js



< script type =text / javascript>

$(function(){

GetCustomers( 1);

});

$([id * = txtSearch])。live(keyup,function(){

GetCustomers(parseInt(1));

});

$(。Pager .page)。live(click,function(){

GetCustomers(parseInt($(this).attr('page')));

});

函数SearchTerm(){

返回jQuery.trim($([id * = txtSearch])。val());

};

函数GetCustomers( pageIndex){

$ .ajax({

类型:POST,

url:CS.aspx / GetCustomers,

数据:'{searchTerm:'+ SearchTerm()+ ',pageIndex:'+ pageIndex +'}',

contentType:application / json; charset = utf-8,

dataType:json,

成功:OnSuccess,

失败:功能(响应){

alert(response.d);

},

错误:函数(响应){

alert(响应。 d);

}

});

}

var row;

函数OnSuccess(响应){

var xmlDoc = $ .parseXML(response.d);

var xml = $(xmlDoc);

var customers = xml.find(PaymentTracker1);

if(row == null){

row = $([id * = GridView1] tr: last-child)。clone(true);

}

$([id * = GridView1] tr)。not($([id * = GridView1] tr:first-child))。remove();

if(customers.length> 0){

$ .each(customers,function(){

var customer = $(this);

$(td,row).eq(0).html( $(this).find(Name)。text());

$(td,row).eq(1).html($(this).find(ID )。text());

$(td,row).eq(2).html($(this).find(InvestmentType)。text());

$(td,row).eq(3).html($(this).find(Amount)。text());

$( td,row).eq(4).html($(this).find(MonthlyPay)。text());

$(td,row).eq( 5).html($(this).find(NumberOfMonths)。text());

$(td,row).eq(6).html($(this) .find(StartDate)。text());

$(td,row).eq(7).html($(this).find(EndDate)。text ());

$(td,row).eq(8).html($(this).find(Phone)。text());

$(td,row).eq(9).html($(this).find(Address)。text());

$([id * = GridView1])。append(row);

row = $([id * = GridView1] tr:last-child)。clone(true);

});

var pager = xml.find(Pager);

$(。Pager)。ASPSnippets_Pager({

ActiveCssClass:当前,

PagerCssClass:pager,

PageIndex:parseInt(pager.find(PageIndex)。text( )),

PageSize:parseInt(pager.find(PageSize)。text()),

RecordCount:parseInt(pager.find(RecordCount)。 text())

});



$(。Name)。each(function(){

var searchPattern = new RegExp('('+ SearchTerm()+')','ig');

$(this).html($(this).text()。 replace(searchPattern,+ SearchTerm()+));

});

} else {

var empty_row = row.clone(true);

$(td:first-child ,empty_row).attr(colspan,$(td,row)。length);

$(td:first-child,empty_row).attr(align,中心);

$(td:first-child,empty_row).html(找不到搜索条件的记录。);

$( td,empty_row).not($(td:first-child,empty_row))。remove();

$([id * = GridView1])。append(empty_row) ;

}

};

< / script>







此查询用于搜索,分页。如何用这个javascript编辑网格





.aspx





< asp:GridView ID =GridView1runat =serverAutoGenerateColumns =falseDataKeyNames =id

OnPageIndexChanging =GridView1_PageIndexChangingOnRowCancelingEdit =GridView1_RowCancelingEdit

OnRowDeleting =GridView1_RowDeletingOnRowEditing =GridView1_RowEditingOnRowUpdating =GridView1_RowUpdating>

< columns> < asp:BoundField HeaderStyle-Width =150pxDataField =IDHeaderText =ID/>

< asp:BoundField HeaderStyle-Width =150pxDataField =Name HeaderText =NameItemStyle-CssClass =ContactName/>

< asp:BoundField HeaderStyle-Width =150pxDataField =InvestmentTypeHeaderText =投资类型/>

< asp:BoundField HeaderStyle-Width =150pxDataField =AmountHeaderText =Amount/>

< asp:BoundField HeaderStyle-Width = 150pxDataField =MonthlyPayHeaderText =每月支付/>

< asp:BoundField HeaderStyle-Width =150pxDataField =NumberOfMonthsHeaderText =Number of Months/> ;

< asp:BoundField HeaderStyle-Width =150pxDataField =StartDateHeaderText =Start Date/>

< asp:BoundField HeaderStyle-宽度=150pxDataField =EndDateHeaderText =结束日期/>

< asp:BoundField HeaderStyle-Width =150pxDataField =PhoneHeaderText =Phone/>

< asp:BoundField HeaderStyle-Width =150pxDataField =Address HeaderText =地址/>

< asp:CommandField ShowEditButton =true/>

< asp:CommandField ShowDeleteButton =true/>

edit is not working in grid when i use following java script, without this javascript code edit is working


js

<script type="text/javascript">
$(function () {
GetCustomers(1);
});
$("[id*=txtSearch]").live("keyup", function () {
GetCustomers(parseInt(1));
});
$(".Pager .page").live("click", function () {
GetCustomers(parseInt($(this).attr('page')));
});
function SearchTerm() {
return jQuery.trim($("[id*=txtSearch]").val());
};
function GetCustomers(pageIndex) {
$.ajax({
type: "POST",
url: "CS.aspx/GetCustomers",
data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
var row;
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var customers = xml.find("PaymentTracker1");
if (row == null) {
row = $("[id*=GridView1] tr:last-child").clone(true);
}
$("[id*=GridView1] tr").not($("[id*=GridView1] tr:first-child")).remove();
if (customers.length > 0) {
$.each(customers, function () {
var customer = $(this);
$("td", row).eq(0).html($(this).find("Name").text());
$("td", row).eq(1).html($(this).find("ID").text());
$("td", row).eq(2).html($(this).find("InvestmentType").text());
$("td", row).eq(3).html($(this).find("Amount").text());
$("td", row).eq(4).html($(this).find("MonthlyPay").text());
$("td", row).eq(5).html($(this).find("NumberOfMonths").text());
$("td", row).eq(6).html($(this).find("StartDate").text());
$("td", row).eq(7).html($(this).find("EndDate").text());
$("td", row).eq(8).html($(this).find("Phone").text());
$("td", row).eq(9).html($(this).find("Address").text());
$("[id*=GridView1]").append(row);
row = $("[id*=GridView1] tr:last-child").clone(true);
});
var pager = xml.find("Pager");
$(".Pager").ASPSnippets_Pager({
ActiveCssClass: "current",
PagerCssClass: "pager",
PageIndex: parseInt(pager.find("PageIndex").text()),
PageSize: parseInt(pager.find("PageSize").text()),
RecordCount: parseInt(pager.find("RecordCount").text())
});

$(".Name").each(function () {
var searchPattern = new RegExp('(' + SearchTerm() + ')', 'ig');
$(this).html($(this).text().replace(searchPattern, "" + SearchTerm() + ""));
});
} else {
var empty_row = row.clone(true);
$("td:first-child", empty_row).attr("colspan", $("td", row).length);
$("td:first-child", empty_row).attr("align", "center");
$("td:first-child", empty_row).html("No records found for the search criteria.");
$("td", empty_row).not($("td:first-child", empty_row)).remove();
$("[id*=GridView1]").append(empty_row);
}
};
</script>



this query for searching, paging . how to edit grid with this javascript


.aspx


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="id"
OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
<columns> <asp:BoundField HeaderStyle-Width="150px" DataField="ID" HeaderText="ID" />
<asp:BoundField HeaderStyle-Width="150px" DataField="Name" HeaderText="Name" ItemStyle-CssClass="ContactName" />
<asp:BoundField HeaderStyle-Width="150px" DataField="InvestmentType" HeaderText="Investment Type" />
<asp:BoundField HeaderStyle-Width="150px" DataField="Amount" HeaderText="Amount" />
<asp:BoundField HeaderStyle-Width="150px" DataField="MonthlyPay" HeaderText="Monthly Pay" />
<asp:BoundField HeaderStyle-Width="150px" DataField="NumberOfMonths" HeaderText="Number Of Months" />
<asp:BoundField HeaderStyle-Width="150px" DataField="StartDate" HeaderText="Start Date" />
<asp:BoundField HeaderStyle-Width="150px" DataField="EndDate" HeaderText="End Date" />
<asp:BoundField HeaderStyle-Width="150px" DataField="Phone" HeaderText="Phone" />
<asp:BoundField HeaderStyle-Width="150px" DataField="Address" HeaderText="Address" />
<asp:CommandField ShowEditButton="true" />
<asp:CommandField ShowDeleteButton="true" />

推荐答案

(function(){

GetCustomers(1);

});
(function () {
GetCustomers(1);
});


([id * = txtSearch])。live(keyup,function(){

GetCustomers(parseInt(1) );

});
("[id*=txtSearch]").live("keyup", function () {
GetCustomers(parseInt(1));
});


(。Pager .page)。live(click,function(){

GetCustomers(parseInt(
(".Pager .page").live("click", function () {
GetCustomers(parseInt(


这篇关于当我使用以下Java脚本时,编辑在网格中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆