在asp.net中,带有引导程序的对话框模式中的Gridview onclick-in会将值返回到模式父页Web表单

Gridview onclick in dialog modal with bootstrap in asp.net return values to modal father page webforms

本文关键字:模式 返回 表单 Web onclick-in 引导程序 asp Gridview 对话框 net      更新时间:2023-09-26

我花了一整天的时间尝试和搜索如何在模态弹出窗口内的网格视图中单击一行,并将这些值返回到模态弹出窗口"父"上的标签/文本框中,我已经在使用javascript打开和关闭模态了。退货可以放在closeModal()中。我只需要一个例子,我看了很多论坛和页面,没有找到这样的。感谢您对的帮助

这是ASP.NET代码

<script>
    function openModal() {
        $('#myModal').modal('show')
    };
    function closeModal() {
        console.log("Sai")
        $('#myModal').modal('hide')
        document.getElementById('<%= lblTeste.ClientID %>').innerHTML = 'Your new value';
        console.log("valor mudado")
    };
  function sendTex(texto) {
        document.getElementById('<%= txtExample.ClientID %>') = texto;
    }
</script>
<asp:Label id="lblSelected" runat="server"></asp:Label>
<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
    <!-- Modal content-->
        <div class="modal-content" runat="server">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
                <asp:TextBox ID="txtBusca" runat="server"></asp:TextBox>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:GridView ID="gvBusca"  OnRowDataBound="OnRowDataBound"
                        OnSelectedIndexChanged="OnSelectedIndexChanged" DataKeyNames="id" 
                        runat="server" GridLines="Horizontal" 
                        BorderStyle="None" CssClass="table table-striped table-hover ">
                        </asp:GridView>
                        <asp:Button ID="btnBusca" runat="server" Text="Button" />
                        <asp:Label id="lblValor" runat="server" Text=""></asp:Label>
                    </ContentTemplate>                       
                </asp:UpdatePanel>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" onclick="closeModal()">Close</button>
            </div>
        </div>
    </div>
</div>

这是背后的代码:

Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvBusca.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        e.Row.Attributes("onclick") = Page.ClientScript.GetPostBackClientHyperlink(gvBusca, "Select$" & e.Row.RowIndex)
        e.Row.Attributes("style") = "cursor:pointer"
    End If
End Sub

Protected Sub OnSelectedIndexChanged(sender As Object, e As EventArgs) Handles gvBusca.SelectedIndexChanged
    Dim index As Integer = gvBusca.SelectedRow.RowIndex
    Dim name As String = gvBusca.SelectedRow.Cells(0).Text
    Dim country As String = gvBusca.SelectedRow.Cells(1).Text
    Dim message As String = "Row Index: " & index & "'nName: " & name + "'nCountry: " & country
    ClientScript.RegisterStartupScript(Page.GetType(), "Desc", "sendText('" + name + "');", True)
End Sub

document.getElementById('<%= txtExample.ClientID %>').value = texto;

我想你忘了在上面的声明中添加.value