Connecting Tech Pros Worldwide Forums | Help | Site Map

how to align control in palceholder control

Newbie
 
Join Date: Dec 2006
Posts: 29
#1: Jul 23 '07
Dear All,
I am making web application using Asp.net 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
Expand|Select|Wrap|Line Numbers
  1.   foreach (ListItem li in CheckBoxListmst.Items)
  2.         {
  3.             if (li.Selected == true)
  4.             {
  5.                 //code added to fetch dropdownlist
  6.                 setting =               ConfigurationManager.ConnectionStrings["StyleSearchConnectionString"];
  7.                 if (setting != null)
  8.                 {
  9.                     conn = new SqlConnection(setting.ConnectionString);
  10.                     cmd = new SqlCommand("Search_display");
  11.                     cmd.CommandType = CommandType.StoredProcedure;
  12.                     cmd.Parameters.Add("@cateid", SqlDbType.VarChar);
  13.                     cmd.Parameters["@cateid"].Value = li.Text.ToString();
  14.  
  15.                     conn.Open();
  16.                     cmd.Connection = conn;
  17.                     try
  18.                     {
  19.                         // added controls
  20.                         Label label = new Label();
  21.                         DropDownList dropdownlist = new DropDownList();
  22.                         label.ID = "label" + li.Text;
  23.                         dropdownlist.ID = "dropdownlist" + li.Text;
  24.                         label.Text = li.Text;
  25.                         rdr = cmd.ExecuteReader();
  26.                         while (rdr.Read())
  27.                         {
  28.                             ListItem ld = new ListItem();
  29.  
  30.                             ld.Text = rdr["disp"].ToString();
  31.                             ld.Value = rdr["mstid"].ToString();
  32.                             dropdownlist.Items.Add(ld);
  33.  
  34.  
  35.                         }
  36.                         PlaceHolder1.Controls.Add(label);
  37.                         PlaceHolder1.Controls.Add(dropdownlist);
  38.  
  39.  
  40.                         Response.Write("<BR >");
  41.                         //added controls end
  42.  
  43.                     }
  44.  
  45.                     catch (SqlException ex)
  46.                     {
  47.                     }
  48.  
  49.  
Please Guide me or atleast give some help full link.
thanks

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#2: Jul 23 '07

re: how to align control in palceholder control


Quote:

Originally Posted by imranabdulaziz

Dear All,
I am making web application using Asp.net 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 ...
Please Guide me or atleast give some help full link.
thanks

Most asp.net controls have a CssClass property. When you create the DropDownList or Label or other web control, you can assign the control a CssClass.

All you have to do is create the CSS file, add the class that outlines how the control should be displayed, reference the CSS file in your aspx page, and assign the controls the appropriate class.

I'd look into how to use CSS.

-Frinny
Reply