0

我正在尝试gridview使用jquery. 我已经修改了现有数据textbox并尝试使用jquery. 但它赋予了旧的价值textbox。中未修改的值textbox

ASPX 代码

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">

    /*javascripts and stylesheets are here*/

    <script type="text/javascript">

        function Navigate() {
            $('#dialogDiv').dialog('open');
        }

        $(document).ready(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 + "</br>";
                        });
                        alert(list)
                    }
                }
            });
        }); 

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    <div id="dialogDiv" title="Type" style="overflow: hidden">
        <div id="TypeDiv" class="divTable">
            <div class="divRow">
                <div class="divColumn">
                    <div>
                        <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="open" EventName="Click" />
                            </Triggers>
                            <ContentTemplate>
                                <asp:GridView ID="Type_GV" runat="server" ShowFooter="True" AutoGenerateColumns="False">
                                    <Columns>
                                        <asp:TemplateField HeaderText="Type">
                                            <ItemTemplate>
                                                <asp:TextBox ID="txtType" runat="server" Text='<%# Bind("Type") %>'></asp:TextBox>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <asp:Button ID="open" runat="server" Text="Open dialog" OnClientClick="Navigate()"
        OnClick="open_Clicked" />
    <br />
    <p>
        <asp:Button ID="btnSaveType" runat="server" OnClick="btnSaveType_Clicked" Style="visibility: hidden;
            display: none;" />
    </p>
</asp:Content>

背后的代码

    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<VehicleType> GetTypeList()
    {
        List<VehicleType> list = new List<VehicleType>()
    {
        new VehicleType{Type="Type1"},
        new VehicleType{Type="Type2"}
    };
        return list;
    }
}

我该如何解决这个问题?

4

1 回答 1

1

你可以使用这个:

当您使用更新面板时,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 + "</br>";
                    });
                    alert(list)
                }
            }
        });
});)

注意:不要删除$(document).ready(function{}))保持原样,并包括这个。

于 2013-07-24T10:25:50.740 回答