Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can Anyone correct the following code:


Error code:



protected void BulletedList3_Click(object sender, BulletedListEventArgs e)
    {
        ListItem li = BulletedList3.Items[e.Index];
        string price = li.ToString();
        price_range = BulletedList3.Items[e.Index].Value;
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
        switch (price_range)
        {
            case "Below Rs.500/-":
                condition = "<500";
                break;
            //case "Rs.500/- to Rs.1000/-":
               
            //    break;
            //case "Rs.1000/- To Rs.2000/-":
                
            //    break;
            default:
                break;
        }
        con.Close();
        price1();
    }
    public void price1()
    {
        if(Convert.ToBoolean(price_range  == "<500"))
        {
            SqlCommand cmd = new SqlCommand("select pro_name,pro_img,price from product where status='A'and type='retail'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataList1.DataSource = ds;
        DataList1.DataBind();
        con.Close(); 
            }

    }
Posted
Comments
Prasad_Kulkarni 22-Nov-11 3:15am    
which string?? you already converted it..
M.Narmatha 22-Nov-11 3:17am    
k.i want to correct this code...how can i get values if i click a options like
below rs.500/-
rs.500/- to rs.1000/-

Which of these questions do you want answered - this one or this one[^]?
What do you want corrected in this code?

Your string to boolean conversion looks ok here.
 
Share this answer
 
This code
C#
if(Convert.ToBoolean(price_range  == "<500"))

will not work. Read this Convert.ToBoolean Method (String)[^]
Instead you will need to do something like the following
C#
if (price_range <= 500)


Edit: I just noticed that price_range is a string?? If so what you are trying to do is just weird and I recommend you to rethink your design.

Well I guess you could do something like this
C#
string price_range = "Below Rs.500/-";
string[] priceRange = price_range.Split(new char[] { '.', '/' });
if (Int32.Parse(priceRange[1]) <= 500)
{
}
 
Share this answer
 
v3

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