views:

310

answers:

2

There is very little code out there that is in VB, and i'm getting stuck all the time. Can someone tell me the VB equivalent of this C# code?

Thx...

<%= 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") %>
A: 

The VB equivalent for your SelectList should be:

Dim yesNo as SelectList = {
    New SelectListItem With { .Text = "Yes, I'll be there", .Value = Boolean.TrueString }, _
    New SelectListItem With { .Text = "No, I can't come", .Value = Boolean.FalseString } _
}

http://www.cynotwhynot.com/blog/post/Does-VBNET-have-Collection-Initializers.aspx

Robert Harvey
Thx, but how would i use this code in an aspx file? I'm reading a book and i'm trying to follow the example. The example goes like this:<body><% using(Html.BeginForm()) { %><p>Your name: <%= Html.TextBox("Name") %></p><p>Your email: <%= Html.TextBox("Email")%></p><p>Your phone: <%= Html.TextBox("Phone")%></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") %><% } %></body>
kevinius
A: 

Thanks TV for pointing me in the right direction... I struggled with nutting the array Constructer Type in VB - It was right there all the time....

Robert's on page 26 of Steven Sanderson's great book, Pro ASP.NET MVC Framework.

Many thanks.

Gordon

<% 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 SelectListItem() { _
           New SelectListItem With {.Text = "Yes, I'll be there", .Value = Boolean.TrueString}, _
           New SelectListItem With {.Text = "No, I can't come", .Value = Boolean.FalseString} _
           }, "Choose an option")%>
    </p>
    <input  type="submit" value="Submit RSVP" /> 

<% End Using%>
Gordon