【问题标题】:GridView RowCommand is not updating the control valueGridView RowCommand 不更新控件值
【发布时间】:2014-10-25 08:12:40
【问题描述】:

我在 Gridview 中有一个 LinkBut​​ton,它会弹出一个 jQuery 弹出框以确认删除。此外,我还触发了 Gridview RowCommand,它应该为 jQuery 弹出框中的文本框赋值。这里的问题是在单击 LinkBut​​ton 后会出现弹出框,但 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">&#215;</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>

【问题讨论】:

  • @HassanNisar 怎么做。你能指导我吗?

标签: c# javascript jquery asp.net gridview


【解决方案1】:

在使用 asp:updatepanel 时,我们必须进行一些更改。如果您使用的是 JQuery,请找到您的 jQuery 函数

您必须添加一个 load() 函数,该函数将添加结束请求 使用页面请求管理器的事件并将注册 jquery 函数(这里是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()">

【讨论】:

    猜你喜欢
    • 2020-01-13
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 2012-04-11
    • 1970-01-01
    • 2012-01-19
    相关资源
    最近更新 更多