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

csharp , asp.net India
  • 11 years 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).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra