我在中繼器控件內的中繼器控件和外部中有一個隱藏字段。下面是我有的asp.code。ASP.NET中繼器控制 - 獲得中繼器控制內的Hiddenfield值
<asp:Repeater ID="rptAccordian" runat="server" OnItemDataBound="rptAccordian_ItemDataBound">
<ItemTemplate>
<div class="s_panel">
<h1>
<a href="#" data-content="Tool tip"><%# Eval("Name") %></a>
</h1>
<div>
<p>
<small><span style="font-family: 'Segoe UI'; font-weight: bold;">Category Objective: </span><span style="font-family: 'Segoe UI'"><%# Eval("Objective") %></span></small>
</p>
<p>
<small><span style="font-family: 'Segoe UI'; font-weight: bold;">Category Riskscore: </span>
<code><%# Eval("Score") %><span>%</span></code></small>
</p>
<p>
<code>
<img src="Content/img/add.png" /><asp:LinkButton ID="Add" runat="server">Add Question</asp:LinkButton>
</code>
</p>
<asp:HiddenField ID="hdnCategoryID" runat="server" Value='<%# Bind("CategoryID") %>' />
</div>
</ItemTemplate>
</asp:Repeater>
<div id="modalpopup">
<asp:Button ID="btnInsertQuestion" runat="server" Text="Save" OnClick="btnInsertQuestion_Click" />
</div>
我的後端代碼如下。
protected void btnInsertQuestion_Click(object sender, EventArgs e)
{
HiddenField hf = (HiddenField)rptAccordian.FindControl("hdnCategoryID");
catID = Convert.ToInt16(hf.Value);
Response.Write("ID is") + catID;
}
有13箇中繼器,每個中繼器都有不同的CategoryID。我有一個鏈接按鈕稱爲添加每個中繼器,當我按下該按鈕,我將打開一個模式彈出,它將有一個按鈕。單擊該按鈕時,我需要顯示屬於該中繼器控件的相應CategoryID,在該控件中單擊ADD鏈接按鈕。
但是,hiddenfield hf顯示爲空,我無法獲得該手風琴隱藏字段的值。
使用此鏈接將會有用。 http://stackoverflow.com/questions/29862571/dropdownlist-is-not-showing-the-selected-value –
你正在尋找一個帶有「hiddenid」id的'HiddenField',但你的aspx裏的實際id是「 hdnCategoryID」。 – dario