无法从gridview中的文本框中获取修改后的值
我正在尝试使用jquery
获取gridview
数据。 我修改了textbox
现有数据,并尝试使用jquery
获取该值。 但它在textbox
给出了旧的价值。 没有修改textbox
值。
ASPX代码
/*javascripts and stylesheets are here*/ function Navigate() { $('#dialogDiv').dialog('open'); } $(document).ready(function () { var list = ""; $('#dialogDiv').dialog({ autoOpen: false, resizable: true, width: 300, height: 'auto', buttons: { "Save": function () { $("# tr").each(function () { //Skip first(header) row if (!this.rowIndex) return; var type = $(this).find("td:last").html(); list += type + ""; }); alert(list) } } }); }); <asp:TextBox ID="txtType" runat="server" Text=''>
代码背后
protected void Page_Load(object sender, EventArgs e) { } protected void open_Clicked(object sender, EventArgs e) { VehicleType vTypeObject = new VehicleType(); Type_GV.DataSource = vTypeObject.GetTypeList(); Type_GV.DataBind(); } protected void btnSaveType_Clicked(object sender, EventArgs e) { foreach (GridViewRow gvr in Type_GV.Rows) { TextBox type = (TextBox)gvr.FindControl("txtType"); Debug.WriteLine("type : " + type.Text); } } public class VehicleType { public string Type { get; set; } public List GetTypeList() { List list = new List() { new VehicleType{Type="Type1"}, new VehicleType{Type="Type2"} }; return list; } }
我怎么解决这个问题?
你可以用这个:
当您使用更新面板时,在异步回发完成并且控件已返回到浏览器后引发this.remove_endRequest()
。
不确定,但我认为这个问题,我多次面对这些问题。 可能对你有所帮助。
见文档
Sys.WebForms.PageRequestManager.getInstance().remove_endRequest($(function(){ var list = ""; $('#dialogDiv').dialog({ autoOpen: false, resizable: true, width: 300, height: 'auto', buttons: { "Save": function () { $("#<%=Type_GV.ClientID %> tr").each(function () { //Skip first(header) row if (!this.rowIndex) return; var type = $(this).find("td:last").html(); list += type + ""; }); alert(list) } } }); });)
注意:不要删除$(document).ready(function{}))
保持原样,并包含这个。