[英]Asp.net client side editing of gridview gets overwritten
I have a simple gridview filled with a list of simple entities 我有一个简单的gridview,其中填充了简单实体的列表
public class Order
{
public int Id { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public int Quantity { get; set; }
}
in the Page_Load method i do the following 在Page_Load方法中,我执行以下操作
if (!IsPostBack)
{
this.magrid.DataSource = list;
magrid.DataBind();
}
my page is defined as so 我的页面定义为
<asp:panel runat="server" ID="MyOrders" Visible="true" Width="900px">
<asp:UpdatePanel runat="server" ID="AjaxPanel">
<ContentTemplate>
<asp:GridView runat="server" ID="magrid" AutoGenerateColumns="False" OnRowDataBound="RowDataBound">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id"/>
<asp:BoundField DataField="Code" HeaderText="Code"/>
<asp:BoundField DataField="Description" HeaderText="Description"/>
<asp:BoundField DataField="Quantity" HeaderText="Quantity"/>
<asp:TemplateField
HeaderText="Action"
ItemStyle-CssClass="gviCnt gviCntProductid"
HeaderStyle-CssClass="gviModifyOrder">
<ItemTemplate>
<asp:LinkButton
OnClientClick='<%# "MettreAZero(" + Eval("Id") + ");" %>'
Visible='true'
Text='Clear' runat="server"
ID="btnRemoveLine"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:panel>
</div>
</form>
and the javascript function as such { 以及javascript函数{
function MettreAZero(id) {
var table = document.getElementById("magrid");
for (var i = 0, row; row = table.rows[i]; i++) {
var cellid = row.cells[0].innerHTML;
if (cellid == id) {
row.cells[3].innerHTML = "0";
return;
}
}
}
}
</script>
the problem I have is that when I click the button, the value of the selected line is changed to zero, but then automatically, the grid is reloaded to its original value. 我遇到的问题是,当我单击按钮时,所选行的值将更改为零,但随后会自动将网格重新加载为其原始值。
What am I missing ? 我想念什么?
thanks 谢谢
In your code you setup a click event handler: 在您的代码中,设置一个单击事件处理程序:
OnClientClick=<%# "MettreAZero(" + Eval("Id") + ");" %>
You should stop the submit event from posting back because you will lose the state you just modified. 您应该停止提交事件回发,因为您将丢失刚修改的状态。 You just need to Modify
MettreAZero()
to return false;
您只需要修改
MettreAZero()
即可return false;
. 。 Another option would be to use AJAX.
另一种选择是使用AJAX。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.