Connecting Tech Pros Worldwide Help | Site Map

Dynamic Radiobuttonlist

Newbie
 
Join Date: May 2007
Posts: 7
#1: May 15 '09
Hi.

I'm trying to make a dynamic radiobuttonlist for my site. I've found the code for it by googling and i get how its done, but i cant see to get my references working. I've added the System.Windows.Forms reference, and "using" at the top of the page. (some more googling told me that that was the appropriate reference) but i'm still getting this error message:

The type or namespace name `RadioButtonList' could not be found. Are you missing a using directive or an assembly reference?(CS0246)

Heres the code for the radiobuttonlist:
Expand|Select|Wrap|Line Numbers
  1. //create dynamic radiobuttonlist 
  2. RadioButtonList rblTest = new RadioButtonList(); 
  3. rdoMoreRooms.ID = "rblTest";
  4. rdoMoreRooms.AutoPostBack = true; 
  5. //rdoMoreRooms.SelectedIndexChanged += new System.EventHandler(this.radioButton_Check_Changed); 
  6. rdoMoreRooms.RepeatDirection = RepeatDirection.Horizontal; 
  7. rdoMoreRooms.Items.Add(new ListItem("Cake", "Cake")); 
  8. phMoreRooms.Controls.Add(rblTest); 
  9. phMoreRooms.Controls.Add(new LiteralControl("<p>"));    
  10.  
  11.  
I've tried to find a tutorial for this, but it seems to be impossible to find. So i'm hoping that someone here knows how to do it :)
Expert
 
Join Date: Jan 2008
Location: York
Posts: 179
#2: May 15 '09

re: Dynamic Radiobuttonlist


Quote:

Originally Posted by vegtard View Post

Hi.

I'm trying to make a dynamic radiobuttonlist for my site. I've found the code for it by googling and i get how its done, but i cant see to get my references working. I've added the System.Windows.Forms reference, and "using" at the top of the page. (some more googling told me that that was the appropriate reference) but i'm still getting this error message:

The type or namespace name `RadioButtonList' could not be found. Are you missing a using directive or an assembly reference?(CS0246)

Heres the code for the radiobuttonlist:

Expand|Select|Wrap|Line Numbers
  1. //create dynamic radiobuttonlist 
  2. RadioButtonList rblTest = new RadioButtonList(); 
  3. rdoMoreRooms.ID = "rblTest";
  4. rdoMoreRooms.AutoPostBack = true; 
  5. //rdoMoreRooms.SelectedIndexChanged += new System.EventHandler(this.radioButton_Check_Changed); 
  6. rdoMoreRooms.RepeatDirection = RepeatDirection.Horizontal; 
  7. rdoMoreRooms.Items.Add(new ListItem("Cake", "Cake")); 
  8. phMoreRooms.Controls.Add(rblTest); 
  9. phMoreRooms.Controls.Add(new LiteralControl("<p>"));    
  10.  
  11.  
I've tried to find a tutorial for this, but it seems to be impossible to find. So i'm hoping that someone here knows how to do it :)

The easiest way to add using statements (if you are using visual studio) is to use the context menu or right click and select Resolve. If the correct DLL is there it will automatically give you a list of all the namespaces that the class exists in.

If you're not sure on the namespace, a quick google on the class name should return the namespace, or just use the MSDN site directly. What you'll find is that the RadioButtonList is actually contained in the System.Web.UI.WebControls namespace.
Reply