【解決方法】グリッドビュー内にあったリ​​ンクボタンを使用して値を取得する方法


グリッドビュー内にあるリンクボタンを使用してこの値を取得し、モーダルを表示したい

ASP.NET
<pre><div id="id01" class="modal">
        <form class="modal-content animate">
      
            <div class="imgcontainer"></div>
            <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
            <div class="container"> 
               <p> This message was rejected by the recipient email system. Please check the recipient's email address and  try resending this message, or contact the recipient directly</p>
                <p> A problem occurred while delivering this message to this email address. Try sending this message again. If the problem continues, please contact your helpdesk.</p>
                <p> The domain name in the email address is incorrect. Check the address.</p>
                <p> Sorry, I couldn't find any host named like(Sample@email.com). Please check the email address and try again.</p>
                <p> The server has tried to deliver this message, without success, and has stopped trying. Please try sending this message again.<br /> If the problem continues, contact your helpdesk.</p>
                <button type="button" runat="server" onclick="document.getElementById('id01').style.display='none'" id="btncancel">Cancel</button>
                <br />
                <asp:Label runat="server" ID="lblError"></asp:Label>
            </div>
        </form>
    </div>

ここにグリッドビューのコードがあります

ASP.NET
<pre><form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnRowCommand="GridView1_RowCommand" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:TemplateField HeaderText="Subject">
                    <ItemTemplate>
                       <<pre><asp:LinkButton ID="LinkButton1"  runat="server" CommandArgument="EmailDetails" CommandName="DisplayEmail" Text='<%# Eval("Subject") %>'></asp:LinkButton>
                    
                
                <%--<asp:BoundField DataField="Subject" HeaderText="Subject Email" />--%>
                <asp:BoundField DataField="Sender" HeaderText="Receiver" />
                <asp:BoundField DataField="DateCreated" HeaderText="Date and Time Sent" />
                <asp:BoundField DataField="DateReceive" HeaderText="Date and Time Received" />
                <asp:BoundField DataField="EmailHeader" HeaderText="Details" />
            
            <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
            <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
            <RowStyle BackColor="White" ForeColor="#330099" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
            <SortedAscendingCellStyle BackColor="#FEFCEB" />
            <SortedAscendingHeaderStyle BackColor="#AF0101" />
            <SortedDescendingCellStyle BackColor="#F6F0C0" />
            <SortedDescendingHeaderStyle BackColor="#7E0000" />
        
    <asp:Label runat="server" ID="lblSubject">

私が試したこと:

しかし今のところ、その値を取得するためのボタンがあります

<button onclick="document.getElementById('id01').style.display='block'" runat="server">List Email Errors</button>

ここにJavaScriptコードがあります

HTML
<pre> <script>
    // Get the modal
    var modal = document.getElementById('id01');
    var modal = document.getElementById('id02');
    // When the user clicks anywhere outside of the modal, close it
    window.onclick = function(event) {
    if (event.target == modal) {
    modal.style.display = "none";
    }
    }
    </script>

誰かが説明したり、表示するのを手伝ってくれますか

document.getElementById('id01')

私のコードのバックエンドで

C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           if (e.CommandName == "DisplayEmail")
           {


           }

           }

解決策 1

サーバーコードからそのdivを表示および非表示にする方法を意味する場合は、divをパネルに変更します(パネルはサーバー側のdivです)

<asp:Panel id="id01" CssClass="modal" runat="server">

...
</asp:Panel>

あなたのコードでできるようになりました

id01.Visible = true; // show
id01.Visible = false; //hide

サーバータグを使用すると、クライアントの ID が変更される可能性があるため、必ずしも id01 であるとは限らないことに注意してください。そのため、JavaScript 経由でアクセスする場合は、コードを更新する必要があります。

onclick="document.getElementById('<%=id01.ClientID%>').style.display='none'" 

コメント

タイトルとURLをコピーしました