簡體   English   中英

如何將選定 Datalist 變量的值從 html 傳輸到代碼隱藏中的 c# 方法?

[英]how to transmit value of selected Datalist variable from html to the c# method in the codebehind?

我有一個 html 頁面,該頁面加載了一個包含候選人信息的數據列表。 每個單元格都有一個按鈕,我希望用戶能夠在他們想要 select 該特定候選人時單擊該按鈕。 所選候選的 Id 應該可以在相應的 c# 代碼中的 OnClick 方法中訪問,以便將其用於后續操作。 我一直在尋找一種方法來做到這一點,但沒有成功。 我希望有人能幫助我。 謝謝你。

在 HTML 中:

<asp:Datalist ID="DataList1" runat="server"   > 
    <ItemTemplate>                
        <table class="table-catalog-candidates">
            <tr>
                <td>
                    <%#Eval("IdCandidate")%>
                    <asp:Button ID="Button1" runat="server" 
                        Text="Invite Candidate" 
                        OnClick="BtnInviteCandidate_Click" />
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:Datalist>

在代碼隱藏中:

protected void BtnInviteCandidate_Click(object sender, EventArgs e)
{
    //several processes follow here…
    //how to transmit the value of the selected “IdCandidate” 
    //from the Datalist to this method and 
    //put it in a variable?
}
<asp:Button ID="Button1" runat="server" Text="Invite Candidate" CommandArgument='<%#Eval("IdCandidate")%>'OnClick="BtnInviteCandidate_Click"  />

然后在代碼后面。

(sender as Button).CommandArgument

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM