点击按钮后,GridView上的类属性不起作用 [英] Class attribute on GridView doesn't work after button click

查看:88
本文介绍了点击按钮后,GridView上的类属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView,您可以在其中编辑行中的信息。所以你可以点击该行并弹出一个可以改变内容的框,然后点击保存。
但是,当我点击保存按钮并尝试点击另一行时,弹出框不再显示。我必须彻底关闭表格,然后再返回并单击一行。如果我不点击保存按钮,它工作正常。我点击一行,关闭弹出框并点击另一行。问题是只有在点击保存按钮后。

I have a GridView where you can edit the information on the row. So you can click on the row and this pop ups a box where can change something, then click on save. But after I click on the save button and try to click on another row the pop up box doesn't show anymore. I have to completely close out of the form then go back in and click on a row. It works fine if I don't click on the save button. I click on a row, close the pop up box and click on another row. The problem is only after the save button is clicked.

GridView:

GridView:

<asp:UpdatePanel ID="updOBSAddress" UpdateMode="Conditional" runat="server" >
                               <ContentTemplate>
                                <asp:GridView runat="server" GridLines="None" ID="GVAddresses"  OnRowDataBound="GVAddresses_RowDataBound"  AutoGenerateColumns="false" CssClass="tblStatus" AllowSorting="false" >                    
                                    <Columns>
                                        <asp:TemplateField HeaderText="Code">
                                            <ItemTemplate><%# Eval("AccountCode") %></ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Name">
                                            <ItemTemplate><%# Eval("Name") %></ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnUpdateOBSAddress" />
                    </Triggers>
                </asp:UpdatePanel> 

代码背后:

Code Behind:

protected void GVAddresses_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        GridView gv = sender as GridView;
        DataRowView drv = e.Row.DataItem as DataRowView;
        //e.Row.Cells[0].Attributes.Add("onclick", "event.stopPropagation();");

        if (drv != null)
        {
            e.Row.Attributes.Add("class", "GVAddressesRow");
            e.Row.Attributes.Add("ID", "GVAddressesRow_" + drv["ID"].ToString());
            e.Row.ToolTip = "Click here to Edit Address";
        }
    }
}

按钮:

protected void btnUpdateOBSAddress_Click(object sender, EventArgs e)
    {

    }

在javascript中,当点击该类时,它应该显示弹出窗口,但是在点击按钮:

In the javascript then when the class is clicked it should show the pop up but this doesn't get called anymore after I click the button:

 $(".GVAddressesRow").click(function (e) {  
            ShowAddOBSAddress(this, e.pageX, e.pageY, "Edit");
            EditOBSAddress($(this).attr("ID")); 
        });


推荐答案

问题是 UpdatePanel 。它使用Ajax刷新GridView,虽然用户没有看到Postback,但DOM仍然发生变化,并且以前的绑定使用 $(。GVAddressesRow)。单击迷路了。这就是为什么你必须在UpdatePanel刷新后再次执行它。

The problem is the UpdatePanel. It refreshes the GridView using Ajax, and although the user does not see a Postback, the DOM is still changes and the previous bindings made with $(".GVAddressesRow").click are lost. That is why you have to execute it again after a UpdatePanel refresh.

你可以使用 PageRequestManager

<script type="text/javascript">
    $(document).ready(function () {
        bindPopup();
    });

    var prm = Sys.WebForms.PageRequestManager.getInstance();

    prm.add_endRequest(function () {
        bindPopup();
    });

    function bindPopup() {
        $(".GVAddressesRow").click(function (e) {
            ShowAddOBSAddress(this, e.pageX, e.pageY, "Edit");
            EditOBSAddress($(this).attr("ID"));
        });
    }
</script>

这篇关于点击按钮后,GridView上的类属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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