Visual Studio .NET - how to align dynamically created webcontrol in placeholder

Asked By imran khan on 23-Jul-07 01:27 AM

Dear All,

I am making web application using C#(Visual Studio2005).

I have checkboxlist(which is populated by all the master filed like category , subcategory ,customer , etc  ). Now based on selection I generates web control label (to name the field) and dropdownlistbox (which is filled by code and its description).   


My problem is all controls comes one after other. I would like label then dropdownlist in a single line. That custlabel and its dropdownlist comes in one line then next say categorylabel  and its dropdownlistbox should align in next line and inbetween them one free line .


My code is  


  foreach (ListItem li in CheckBoxListmst.Items)


            if (li.Selected == true)


                //code added to fetch dropdownlist

                setting =               ConfigurationManager.ConnectionStrings["StyleSearchConnectionString"];

                if (setting != null)


                    conn = new SqlConnection(setting.ConnectionString);

                    cmd = new SqlCommand("Search_display");

                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@cateid", SqlDbType.VarChar);

                    cmd.Parameters["@cateid"].Value = li.Text.ToString();



                    cmd.Connection = conn;



                        // added controls

                        Label label = new Label();

                        DropDownList dropdownlist = new DropDownList();

                        label.ID = "label" + li.Text;

                        dropdownlist.ID = "dropdownlist" + li.Text;

                        label.Text = li.Text;

                        rdr = cmd.ExecuteReader();

                        while (rdr.Read())


                            ListItem ld = new ListItem();


                            ld.Text = rdr["disp"].ToString();

                            ld.Value = rdr["mstid"].ToString();









                        Response.Write("<BR >");

                        //added controls end




                    catch (SqlException ex)





Please Guide me or atleast give some help full link.



Controls that have been created dynamically - Peter Bromberg replied to imran khan on 23-Jul-07 07:32 AM

need to have the same HTML / CSS attributes as any other control in order to get the layout you want. So, you are going to have to add more than just the controls.