将Jquery值分配给ASP文本框

时间:2019-05-22 08:33:12

标签: jquery asp.net gridview

我正在尝试将JQuery变量分配给gridview内的ASP.NET文本框。这是我的ASP代码-

<label id="test" runat="server"></label>
<asp:HiddenField ID="hdnexclname" runat="server" />
<div class="container">
            <div class="modal fade" id="detailModal">
                <div class="modal-dialog">
                    <!-- Modal content-->
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title">Edit Record</h4>
                        </div>
                        <div class="modal-body">
                            <asp:UpdatePanel ID="updatepanel" runat="server">
                                <ContentTemplate>
                                    <asp:GridView ID="gvCosttoServeEditMultiple" runat="server" BorderStyle="Solid" BorderWidth="1px"
                                        BorderPadding="5" ForeColor="DarkBlue" BackColor="White" Font-Names="Verdana"
                                        Font-Size="10pt" CellPadding="1" ShowFooter="False" AutoGenerateColumns="False"
                                        DataKeyNames="FY_BIMONTHLY_PERIOD,GA_CODE_CTY,VALUE" Visible="true">
                                        <Columns>

                                            <asp:TemplateField>
                                                <HeaderTemplate>
                                                    <asp:Label ID="lblFY1" runat="server" Text="BIMONTHLY"></asp:Label>
                                                </HeaderTemplate>

                                                <ItemTemplate>
                                                    <div class="div1">
                                                    <asp:TextBox ID="txtFY" runat="server" Enabled="false" CssClass="abc" Text="abc" ClientIDMode="Static" ></asp:TextBox>
          </div>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField>
                                                <HeaderTemplate>
                                                    <asp:Label ID="lblCountryhdedit" runat="server" Text="Country"></asp:Label>
                                                </HeaderTemplate>
                                                <ItemTemplate>

                                                    <asp:TextBox ID="txtcountryedit" runat="server" Enabled="false" Text="pqrs"></asp:TextBox>

                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField>
                                                <HeaderTemplate>
                                                    <asp:Label ID="lblvlhd" runat="server" Text="Results(kLC)"></asp:Label>
                                                </HeaderTemplate>
                                                <ItemTemplate>

                                                    <asp:TextBox ID="txtvl" runat="server" onkeypress="return numericOnly(this)" Text="1234"></asp:TextBox>

                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </div>
                        <div class="modal-footer">

                            <asp:Button ID="btnUpdate" class="btn btn-default" Width="50" Style="height: 15;"
                                runat="server" CommandName="btnUpdate_Name" CommandArgument="btnUpdate_Argument"
                                Text="Save" ViewStateMode="Enabled" />
                            <button id="btnClose" type="button" class="btn btn-default" data-dismiss="modal" runat="server"
                                causesvalidation="false">
                                Close</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>




 $(function () {
                    var data = [];
                    $("#btnedit").click(function () {

                        $("#gvCost input[type=checkbox]:checked").each(function (i) {

                            var row1 = $(this).closest("td").next("td")[0];
                            var row2 = $(this).closest("td").next("td").next("td")[0];
                            var row3 = $(this).closest("td").next("td").next("td").next("td")[0];

                            var $test = $("#div1").find(".abc").val();

                            $('#<%=hdnexclname.ClientID %>').val(row1);
                            $('#test').val(row1);

                            alert($('#test').val(row1));

                            alert($('#<%=hdnexclname.ClientID %>').val(row1));

                            if (typeof row1 === "undefined") {
                                row1 = "";
                            } else {



                            }

                            if (typeof row2 === "undefined") {
                                row2 = "";
                            } else {

                            }

                            if (typeof row3 === "undefined") {
                                row3 = "";
                            } else {

                            }

                            console.log(row2);
                            console.log(row3);

                        });
                        $('#detailModal').modal('show');
                        return false;
                    });
                });

我总是会警惕“未定义” “ [对象对象]” 。也许我在犯一些愚蠢的错误,但无法弄清楚。需要一些帮助来解决此问题。 这是我已经尝试过的-

var $txt = $item[0];

var $test = $($txt).val('text...');

var $test = $('#<%=gvCosttoServeEditMultiple.ClientID %>').find('input:text[id$="txtFY"]').val('Your value.');

var $arrT = $('#<%=gvCosttoServeEditMultiple.ClientID %>').find('input:text[id$="txtFY"]');

var $test = $("#gvCosttoServeEditMultiple").find(".abc").val();

var $country = $(this).find('input:text[id="txtfy"]').val();

0 个答案:

没有答案