PrepAway - Latest Free Exam Questions & Answers

You need to dynamically add values to the end of the drop-down list

You are implementing an ASP.NET page that includes the following down list.
<asp:PlaceHolder ID=”dynamicControls” runat=”server”>
<asp:DropDownList ID=”MyDropDown” runat=”server”>
<asp:ListItem Text=”abc” value=”abc” />
<asp:ListItem Text=”def” value=”def” />
</asp:DropDownList>
</asp:PlaceHolder>
You need to dynamically add values to the end of the drop-down list. What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Add the following OnPreRender event handler to the asp:DropDownList
Private Sub mydropdown_PreRender(ByVal sender As Object, ByVal e As System.
EventArgs) Handles mydropdown.PreRender
Dim ddl As DropDownList = TryCast(sender, DropDownList)
Dim lbl As Label = New Label()
lbl.Text = “Option”
lbl.ID = “Option”
ddl.Controls.Add(lbl)
End Sub

B.
Add the following OnPreRender event handler to the asp:DropDownList
Private Sub mydropdown_PreRender(ByVal sender As Object, ByVal e As System.
EventArgs) Handles mydropdown.PreRender

Dim ddl As DropDownList = TryCast(sender, DropDownList)
ddl.Items.Add(“Option”)
End Sub

C.
Add the following event handler to the page code-behind.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim ddl As DropDownList = TryCast(Page.FindControl(“mydropdown”),
DropDownList)
Dim lbl As Label = New Label()
lbl.Text = “Option”
lbl.ID = “Option”
ddl.Controls.Add(lbl)
End Sub

D.
Add the following event handler to the page code-behind.
Private Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.
EventArgs) Handles Me.LoadComplete
TryCast(Page.FindControl(“mydropdown”), DropDownList)
ddl.Items.Add(“Option”)
End Sub

One Comment on “You need to dynamically add values to the end of the drop-down list


Leave a Reply