Hi there,
Using ASP.NET, there is no real need to do this with JavaScript (well, you could, but you don't have to).
Here's a short example of what I think might help:
Add the following code to an ASPX page, between the <form> tags:
Code:
<asp:ListBox id=ListBox1 runat="server" Width="151px" Height="100px" Rows="5"></asp:ListBox>
<br/>
<asp:Button id=Button1 runat="server" Text="Send"></asp:Button>
<br/>
<asp:Label id=Label1 runat="server"></asp:Label>
This code sets up a Listbox to hold the various choices, a Button that the user can click to submit their choice to the server, and a Label to display the text of the selected item.
Then, in your Code Behind file, add the following code:
Code:
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
String[] arrTest = new String[3];
arrTest[0] = "Apples";
arrTest[1] = "Oranges";
arrTest[2] = "Pears";
ListBox1.DataSource = arrTest;
ListBox1.DataBind();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = ListBox1.SelectedItem.Text;
}
At run time, when the page is requested for the first time (IsPostBack is not true), an array is declared, 3 items are added and then the array is assigned to the Listbox.
When the user clicks the button, the text of the selected item is displayed on the Label.
Note that this is just a simple example. For more information, I suggest you take a look at the Quick Start examples that come with the .NET Framework SDK.
If you have more questions (or need help with a
VB.NET instead of a C# solution), feel free to post them here.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.