Syntax_error[
^]
Use this corrected code..
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SortedList s1 = new SortedList();
s1.Add("01", "C");
s1.Add("04", "sql server");
s1.Add("03", ".net");
s1.Add("02", "c++");
s1.Add("06", "java");
s1.Add("05", "oracle");
ListBox1.DataValueField = "key";
ListBox1.DataTextField = "value";
ListBox1.DataSource = s1;
ListBox1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string c = string.Empty;
for (int i = 0; i < ListBox1.Items.Count; i++)
if (ListBox1.Items[i].Selected)
c += ListBox1.Items[i].Text + "<br/>" + ListBox1.Items[i].Value;
Label1.Text = "Name:" + TextBox1.Text + "<br/> Selected Courses<br/>" + c;
}
ASPX:
<form id="form1" runat="server">
<asp:ListBox SelectionMode="Multiple" ID="ListBox1" runat="server"></asp:ListBox>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Button1_Click" />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>