Community discussion forum

How to display products in dropdownlist order by category in label using div.innerhtml

  • 6 months ago

    Hi,

    i need to show the products in dropdownlist order by category in label using div1.innerhtml.

    i am having sql query for display the products oredr by category.

    "select p.productname, p.productid, c. categoryname from ProductTable p innerjoin CategoryTable c on c.Itemid=p.categoryId order by c.catgeoryname, p. productname"

    	   Page_Load()
                  {
                    Conn.Open();
                    constr = "select p.productname, p.productid, c. categoryname from ProductTable p innerjoin CategoryTable c on c.Itemid=p.categoryId order by c.catgeoryname, p. productname";
                    SqlCommand Cmd = new SqlCommand(constr, Conn);
                    SqlDataReader dr= Cmd.ExecuteReader();
    
                    string cn1;
                    cn1 = "";
    
                    while (dr.Read())
       	    {
    
                     cn1 += dr["categoryname "].ToString() + "<br />";
    
                    }
    
                    div1.InnerHtml = cn1;
    
                    dr.Close();
    
    	    Conn.Close();
    	}
    

    In first loop the empty value assign in new variable. it goes to show categoryname in label

    In second loop need to check the if categoryname is same - it goes to show the products in dropdownlist by category wise else if categoryname is different - it goes to show the catgeoryname in new label.

    how can i write code for this?

    Many thanks.

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback