不能从文本框在GridView控件修改后的值 [英] Can't get modified value from textbox in gridview

查看:102
本文介绍了不能从文本框在GridView控件修改后的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用的jQuery 获得 GridView控件数据。我已经修改的文本现有数据并尝试使用的jQuery 来获取价值。但它给在文本旧值。在文本框不修改的值

I'm trying to get gridview data using jquery. I have modified existing data on textbox and try to get that value using jquery. but it gave old value in textbox. not modified value in textbox.

ASPX code

<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>

后面的 code

    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;
    }
}

我怎样才能解决呢?

How can i solve this ?

推荐答案

您可以使用这样的:

当你正在使用更新的面板, this.remove_endRequest()异步回发完成并控制已经​​返回给浏览器后升高。

As you are using the update panels, this.remove_endRequest() is raised after an asynchronous postback is finished and control has been returned to the browser.

不知道,但我觉得这个问题,我面对这类问题很多次。也许对你有所帮助。

Not sure but i think this the issue, i faced these kind of issues many times. Might be helpful to you.

见文档

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)
                }
            }
        });
});)

注意:不要删除 $(文件)。就绪(函数{}))保持它,因为它是,并且包括这之一。

Note: Don't remove $(document).ready(function{})) keep it as it is, and include this one.

这篇关于不能从文本框在GridView控件修改后的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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