从中继器中的控件中检索值

时间:2018-12-09 19:52:23

标签: asp.net .net vb.net

我目前正在使用vb.net进行在线测验。使用以下代码,我从数据库中检索了值并将其分配给一个dropdownlist控件

<asp:Repeater runat="server" ID="repeater1">
<ItemTemplate> 
    <div style="text-align:center;width:100px;">
    <%#Eval("Question").ToString %>
        <uc1:DropDownList runat="server" ID="DropDownList1"   />
    </div>
    <br />
</ItemTemplate>

Private Sub repeater1_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles repeater1.ItemDataBound
    Dim rowview As DataRowView = CType(e.Item.DataItem, DataRowView)
    Dim ddlAnswers As App_Controls_Forms_DropDownList = CType(e.Item.FindControl("DropDownList1"), App_Controls_Forms_DropDownList)
    Dim QuizQuestionsID As Integer = CInt(rowview.Item("QuizQuestionsID"))

    If (e.Item.ItemType = ListItemType.Item) OrElse (e.Item.ItemType = ListItemType.AlternatingItem) Then

        ddlAnswers.LookupNameWithLookupIDAsEnumByID = QuizQuestionsID


    End If

End Sub

此行ddlAnswers.LookupNameWithLookupIDAsEnumByID = QuizQuestionsID为下拉列表提供选项。

因此,我可以使所有问题与下拉列表中的更正选项一起出现。但是,单击按钮后,如何返回已选择的选项?如果要渲染的下拉列表有5个,而转发器中只有一个

.net的新手,谢谢您的帮助

0 个答案:

没有答案