Populating an ASP.Net DropDownList using VB.Net coding in code-behind file

天涯浪子 提交于 2019-12-05 16:31:47

Try and populate your DropDownList in the DropDownList_Init event handler.

Markup:

<asp:DropDownList ID="ddlTheDropDownList" runat="server" OnInit="ddlTheDropDownList_Init">

The code behind should look something like this, I'm more used to C# but I hope you understand the point:

Protected Sub ddlTheDropDownList_Init(sender As Object, e As EventArgs)
    Dim ddl As DropDownList
    ddl = sender As DropDownList
    ddl.Datasource = theClassesTableAdapter.GetDataByAllClasses
    ddl.DataTextField = "ClassName"
    ddl.DataValueField = "ClassID"
    ddl.SelectedValue = "ClassID"
    ddl.DataBind()
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!