gpt4 book ai didi

javascript - Asp.Net 在按钮单击时将值从 GridView 传递到模态文本框

转载 作者:行者123 更新时间:2023-11-28 03:24:05 26 4
gpt4 key购买 nike

如上所述,我想知道如何将数据从 gridview 发送到模态 Asp:TextBox

GridView按钮

<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<a data-id="<%#Eval("BookFile") %>" title="Add this item" class="openDialog">Open Modal</a>
</center>
</ItemTemplate>
</asp:TemplateField>

脚本

<script type="text/javascript">
$(function () {
$(".openDialog").click(function () {
$('#Id').val($(this).data('id'));
$("#addDialog").modal("show");
});
});
</script>

模态

   <div class="modal fade" id="addDialog" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">

<!-- Modal Head -->
<div class="modal-header">
<h5 class="modal-title" id="myModal1">Modal title</h5>
</div>

<!-- Modal Body -->
<div class="modal-body">

<div class="form-group">
<asp:Label runat="server" AssociatedControlID="bookId1" CssClass="col-md-2 control-label">Username</asp:Label>
<div class="col-md-10">
<asp:TextBox runat="server" ID="Id" CssClass="form-control"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="Id"
CssClass="text-danger" ErrorMessage="The field is required." />
</div>
</div>

</div><!--End tag of Modal Body -->

<!-- Modal Footer -->
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<asp:Button runat="server" OnClick="CreateUser_Click" Text="Add User" CssClass="btn btn-Success" />
</div>


</div>
</div>
</div>

每当我使用它时,不会将任何数据填充到文本框中,但每当我使用输入框时,代码就会起作用

<input type="text" name="Id" id="Id"> 

提前致谢!

最佳答案

好的。我只需更改脚本即可解决此问题

<script type="text/javascript">
$(function () {
$(".openDialog").click(function () {
$('#Id').val($(this).data('id'));
$("#addDialog").modal("show");
});
});
</script>

<script type="text/javascript">
$(function () {
$(".openDialog").click(function () {
document.getElementById("<%=Id.ClientID%>").value = $(this).data('id');
$("#addDialog").modal("show");
});
});
</script>

关于javascript - Asp.Net 在按钮单击时将值从 GridView 传递到模态文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58832479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com