我在Gridview中有一个LinkButton,弹出一个jQuery弹出框以进行删除确认。此外,我已经触发了Gridview RowCommand,它应该为jQuery弹出框内的文本框赋值。这里的问题是在LinkButton单击后出现弹出框,但RowCommand事件没有为文本框赋值。实际上,文本框会恢复到旧的默认值。
我搜索过这个问题太多但无法得到正确的解决方案。以下是我的代码,任何帮助都非常明显。
//The code behind GridView_RowCommand event
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string arguments = e.CommandName + " - " + e.CommandArgument.ToString() + " - " + e.CommandSource.ToString();
if (e.CommandName == "Delete")
{
txt.Text = e.CommandArgument.ToString();
}
}
//Page Source
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="myModal" class="reveal-modal">
<h1>Delete</h1>
<p>This will guide you through the delete process</p>
<asp:TextBox ID="txt" runat="server"></asp:TextBox>
<p><asp:Button ID="Button2" runat="server" Text="Button" /></p>
<a class="close-reveal-modal">×</a>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="RBUEntityDataSource" CssClass="gridview" OnRowCommand="GridView1_RowCommand" EnableViewState="True">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Region" HeaderText="Region" ReadOnly="True" SortExpression="Region" />
<asp:TemplateField HeaderText="Update">
<ItemTemplate>
<asp:LinkButton ID="lbUpdate" runat="server" CommandName="Update" OnClick="lbUpdate_Click">Update</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="lbDelete" class="big-link" data-reveal-id="myModal" runat="server" CommandName="Delete" CommandArgument='<%# Eval("Id") %>'>Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:EntityDataSource ID="RBUEntityDataSource" runat="server" ConnectionString="name=ChemonicsDBEntities" DefaultContainerName="ChemonicsDBEntities" EnableFlattening="False" EntitySetName="RegionalBusinessUnits" Select="it.[Id], it.[Region]" OrderBy="it.[Id] asc" Where="it.[DeletedBy] = 0">
</asp:EntityDataSource>
</ContentTemplate>
</asp:UpdatePanel>
答案 0 :(得分:0)
在使用asp:updatepanel时,我们必须进行一些更改。如果您使用的是JQuery,那么找到您的jQuery函数
您必须添加一个load()函数,该函数将添加End Request 使用Page Request Manager的事件,并将注册jquery function(这里是jsFunctions)
喜欢这个
<script language="javascript" type="text/javascript">
function load() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(jsFunctions);
}
function jsFunctions() {
$("#btnClick").click(function () {
alert("Alert");
});
}
</script>
最后
<body onload="load()">