我在后端代码中找不到我的hiddenfield2

时间:2017-03-19 21:10:19

标签: html asp.net vb.net

我在后端代码中找不到我的hiddenfield2。那么如何使用asp.net(vb)

获取此hiddenfiled的值
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <div class="list_election">
          <form>
       <asp:DropDownList ID = "ddlElectionCategorie" runat="server" AutoPostBack="true">
    </asp:DropDownList>

          </form>
      </div>
     <div class="row">
    <asp:Repeater ID="rpVoteList" runat="server" >

        <ItemTemplate>

            <div class="col-md-4 ">
                <div class="voter">
                    <h4><%# Eval("List_Nom")%></h4>

                    <asp:HiddenField ID="hfListId" runat="server" Value='<%# Eval("Id")%>' />
                    <form>
'this is a nested radiobutton list in a repeater
                         <asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Eval("Id")%>' />
                        <asp:RadioButtonList ID="RbCandidat" runat="server"></asp:RadioButtonList>

                    </form>

                </div>
            </div>


        </ItemTemplate>

    </asp:Repeater>
     </div>
    <asp:Button ID="Button1" runat="server" Text="Button" />
</asp:Content>

1 个答案:

答案 0 :(得分:1)

C#:

foreach (RepeaterItem item in rpVoteList.Items)
{
    if (item.ItemType == ListItemType.Item || item.ItemType ==  ListItemType.AlternatingItem)
    {
        var hf= (HiddenField)item.FindControl("HiddenField2")
    }
}

或者

protected void rpVoteList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    var value = (HiddenField) e.Item.FindControl("HiddenField2")).Value;
}