Newbie question

S

slinky

This I know is basic stuff, but I can't get it to work me. What I'm
trying to do is have a DropDownList populated by an array. I'm using
Visual Web Studio Express 2005. I need to put the below code somewhere
in my main code. Thanks in advance!
_________________________________________________

Public arrData As String() = {"Yankees", "Mets", "Cardinals"}

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Page.DataBind()
End Sub
________________________________________________

<%@ Page Language="VB" EnableSessionState="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">

<div>
<asp:DropDownList ID="DropDownList1" runat="server"
EnableViewState="False" Width="271px"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
OnDataBinding="arrData" OnDataBound="Page_Load">

</asp:DropDownList></div>

</form>
</body>
</html>
 
S

slinky

DropDownList1.DataSource=yourArray
DropDownList1.DataBind()

Thanks but I still need some basics of where to place this block of
code... I tried the below but got a reuntime error... any more clues
would help... Thanks!

<%@ Page Language="VB" EnableSessionState="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Public arrData As String() = {"Yankees", "Mets", "Cardinals"}

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DropDownList1.DataSource = arrData
DropDownList1.DataBind()
End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">

<div>
<asp:DropDownList ID="DropDownList1" runat="server"
EnableViewState="False" Width="271px"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
OnDataBinding="arrData" OnDataBound="Page_Load">

</asp:DropDownList></div>

</form>
</body>
</html>
 
G

Guest

<%@ Page Language="VB" EnableSessionState="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Public arrData As String() = {"Yankees", "Mets", "Cardinals"}
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DropDownList1.DataSource = arrData
DropDownList1.DataBind()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server"
EnableViewState="False" Width="271px">
</asp:DropDownList></div>
</form>
</body>
</html>


-- You need to spend some time studying how this all works, or you'll be
forever asking questions on newgroups and waiting for answers!
Cheers,
Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top