在“网格”视图中输入关键文本框未获得ID的行选择

时间:2019-02-13 06:18:31

标签: javascript c# ajax gridview

在单元格中填充数据后,我想在gridview的第4列中编辑数据。保存时,我只能保存第一行。

请帮助我,我试图尝试所有建议。

function controlEnter(obj, event) {
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
        if (keyCode == 13) {
            var time = $('[id*=txtdateN]').val();
            var row = $(this).closest("tr");
            var KULNid = $('[id*=txtID]').val();
            var Grid_EnterKey = document.getElementById(obj);
            var gKANRIZU_NO = obj;   
            var gSOK1 = $(this).closest('tr').find('.SOK1').val();
            var gSOK2 = $(this).closest('tr').find('.SOK2').val();
            var gSOK3 = $(this).closest('tr').find('.SOK3').val();
            var gSOK4 = $(this).closest('tr').find('.SOK4').val();
            $.ajax({
                type: "POST",
                url: "WebService.asmx/UpdategridG",
                data: "{'KULN' :'" + KULNid + "', 'KANRIZU_NO': '" + gKANRIZU_NO + "' ,'SOK1': '" + gSOK1 + "' , 'SOK2': '" + gSOK2 + "' , 'SOK3': '" + gSOK3 + "', 'SOK4' : '" + gSOK4 + "','time' : '" + time + "' }",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                error: OnErrorCall_
            });

            function OnErrorCall_(repo) {

                alert("Something went wrong, pls check setting");
            }
        }
        else {
            return true;
        }
    }
    </script>
<asp:TemplateField HeaderText="SOK1" HeaderStyle-CssClass="text-center" ItemStyle-BackColor="#f4f7c9">
                        <ItemTemplate>
                            <asp:Label ID="lblSOK1" runat="server"></asp:Label>
                            <asp:TextBox ID="txtSOK1" ReadOnly="false" runat="server" CssClass="SOK1 hideControl form-control"></asp:TextBox> 
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txt01" ReadOnly="false" runat="server"></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="SOK2" HeaderStyle-CssClass="text-center" ItemStyle-BackColor="#f4f7c9">
                        <ItemTemplate>
                            <asp:Label ID="lblSOK2" runat="server"></asp:Label>
                            <asp:TextBox ID="txtSOK2" ReadOnly="false" runat="server" CssClass="SOK2 hideControl form-control"></asp:TextBox>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txt02" ReadOnly="false" runat="server"></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="SOK3" HeaderStyle-CssClass="text-center" ItemStyle-BackColor="#f4f7c9">
                        <ItemTemplate>
                            <asp:Label ID="lblSOK3" runat="server"></asp:Label>
                            <asp:TextBox ID="txtSOK3" ReadOnly="false" runat="server" CssClass="SOK3 hideControl form-control"></asp:TextBox>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txt03" ReadOnly="false" runat="server"></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="SOK4" HeaderStyle-CssClass="text-center" ItemStyle-BackColor="#f4f7c9">
                        <ItemTemplate>
                            <asp:Label ID="lblSOK4" runat="server"></asp:Label>
                            <asp:TextBox ID="txtSOK4" runat="server" CssClass="SOK4 hideControl form-control"></asp:TextBox>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txt04" runat="server"></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>

1 个答案:

答案 0 :(得分:0)

只需传递要更新和更新的ClientID的ClientID的唯一列(按ID)

在ajax中

data: {'ClientID': ClientID, 'others parames'},

例如

$sql = "updated table set column1=value Where ClientID=20";

希望这对您有帮助