Working through Pro ASP.NET MVC book and I got the following code snippet that appears in an aspx (view) page…
<%= Html.DropDownList ("WillAttend",new[]
{
new SelectListItem { Text = "Yes, I'll be there",Value=bool.TrueString},
new SelectListItem { Text = "No, I can't come",Value=bool.FalseString}
},"Choose an option"); %>
Can someone help me convert this to vb.net equivalent.
Any ideas anyone?
EDIT
MORE DETAILS
Here is the whole code snippet. Not sure it will help but here it goes.
<body>
<h1>RSVP</h1>
<% using(Html.BeginForm()) { %>
<p> Your name: <%= Html.TextBox("Name") %></p>
<p> Your email: <%= Html.TextBox("Email") %></p>
<p> Your phone: <%= Html.TextBox("Phone") %></p>
<p>
Will you attend?
<%= Html.DropDownList ("WillAttend",new[]
{
new SelectListItem { Text = "Yes, I'll be there",Value=bool.TrueString},
new SelectListItem { Text = "No, I can't come",Value=bool.FalseString}
},"Choose an option") %>
</p>
<input type="submit" value="Submit RSVP" />
<% } %>
</body>
Any help appreciated. I REALLY can’t figure this one out.
Seth
you can do this with some fairly verbose VB.NET code:
The trick is to read the function arguments and supply the appropriate parameters. Sometimes we get used to the more arcane syntaxes and forget about simple variable declarations and assignments. The DropDownList expects an IEnumerable of SelectListItem’s as the second argument so that’s what we give it. Each SelectListItem should probably have it’s value and text fields supplied. What I don’t understand is why the SelectListItem’s constructor does not supply those two items (plus perhaps a “selected” boolean.)