Click here to Skip to main content
15,885,143 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi iam getting a small issue in default.aspx.cs page
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.Globalization;
using System.IO;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
namespace sortedlist
{
    public partial class _Default : System.Web.UI.Page
    {
        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 ();
                {
                string c=string.Empty;
                    for (int t=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;
}
            }
        }
    }
}
Posted
Comments
_Damian S_ 29-Jan-14 23:48pm    
It's traditional to tell us specifically what your small issue is, including any error messages you may be receiving.
harshavardhan12345678 29-Jan-14 23:50pm    
Error 2 ) expected c:\visual studio 2010\Projects\sortedlist\sortedlist\Default.aspx.cs 35 57 sortedlist
Error 1 ; expected c:\users\mr003\documents\visual studio 2010\Projects\sortedlist\sortedlist\Default.aspx.cs 35 56 sortedlist
Error 4 ; expected c:visual studio 2010\Projects\sortedlist\sortedlist\Default.aspx.cs 35 60 sortedlist
Error 5 ; expected c:\visual studio 2010\Projects\sortedlist\sortedlist\Default.aspx.cs 35 61 sortedlist
Error 3 Invalid expression term ')' c:documents\visual studio 2010\Projects\sortedlist\sortedlist\Default.aspx.cs 35 60 sortedlist
Message 6 Validation (XHTML 1.0 Transitional): Attribute 'align' is considered outdated. A newer construct is recommended. c:visual studio 2010\Projects\sortedlist\sortedlist\Default.aspx 23 16 sortedlist
harshavardhan12345678 29-Jan-14 23:53pm    
error
for (int t=0;i<ListBox1.Items.Count,i++)
harshavardhan12345678 29-Jan-14 23:57pm    
issue solved
JoCodes 29-Jan-14 23:49pm    
Post the error message you are getting.

1 solution

Syntax_error[^]

Use this corrected code..

C#
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:

XML
<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>
 
Share this answer
 
v2
Comments
harshavardhan12345678 30-Jan-14 0:03am    
bro error
last line----the name c doesn't exist in current context
Karthik_Mahalingam 30-Jan-14 0:06am    
use my updated code..
harshavardhan12345678 30-Jan-14 0:13am    
Warning 1 19 5 sortedlist
Error 2 The name 'c' does not exist in the current context c:visual studio 2010\Projects\sortedlist\sortedlist\Default.aspx.cs 42 85 sortedlist
Karthik_Mahalingam 30-Jan-14 0:23am    
post your code.
harshavardhan12345678 30-Jan-14 0:25am    
issue solved...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900