tverney Posted June 21, 2005 Posted June 21, 2005 I am trying to add a dropdownlist to a web form and failing I have the following code: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim x As New DropDownList() With x .Font.Bold = True .Style.Add("position", "absolute") .Style.Add("left", "420px") .Style.Add("top", "50px") .Style.Add("Width", "250px") End With Controls.Add(x) End Sub I recieve the following message: Control '_ctl0' of type 'DropDownList' must be placed inside a form tag with runat=server. If I change: Dim x As New DropDownList() To Dim x As New Label() it runs Any thoughts? Thanks! Quote
kahlua001 Posted June 21, 2005 Posted June 21, 2005 Add a place holder in between the <form> tags, and then add your dropdown to this place holder. Quote
bri189a Posted June 21, 2005 Posted June 21, 2005 Is there a reason why you can't have the control already on the page and just change it's visiblity states? That would be a lot easier to wire up events to also. Quote
tverney Posted June 22, 2005 Author Posted June 22, 2005 Found the answer Is there a reason why you can't have the control already on the page and just change it's visiblity states? That would be a lot easier to wire up events to also. Hey, thanks for the response. Yes, I'm writing web front end to launch a Crystal Report. The Crystal report takes parameters. The front end will allow the user to input the parameters and then launch the report. The only rub here is that there are several hundred, yes, several hundred different reports that need input screens. Didn't write them, just have to manage them. I've written the code that will interrogate a report for it's parameters and insert records in the appropriate SQL tables. BTW, found the answer to my question. The corrected code follows. The drParm datarow contains information about the combobox properties. Sub AddComboBox(ByVal drParm As DataRow) Dim dsParms As New DataSet() dsParms = o_DataExpert.GetSPData(drParm.Item("ParmCommand"), dsParms) Dim x As New DropDownList() With x '.Font.Bold = True .Style.Add("position", "absolute") .Style.Add("left", drParm.Item("ParmLeft")) .Style.Add("top", drParm.Item("ParmTop")) .Style.Add("Width", drParm.Item("ParmWidth")) .DataSource = dsParms.Tables(drParm.Item("ParmCommand")) .DataValueField = dsParms.Tables(drParm.Item("ParmCommand")).Columns(0).ColumnName() ' typically an ID Field .DataTextField = dsParms.Tables(drParm.Item("ParmCommand")).Columns(1).ColumnName() ' what user will see .DataBind() .ID = drParm.Item("ParmName") End With 'this is the line that was missing Page.FindControl("Form1").Controls.Add(x) ' a couple of links that provided guidance 'http://www.pcreview.co.uk/forums/thread-1261472.php 'http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.Aspx?ArticleID=4322 End Sub Quote
flann Posted September 9, 2005 Posted September 9, 2005 Add a place holder in between the <form> tags' date=' and then add your dropdown to this place holder.[/quote'] How do you add a placeholder? Quote Flann Mortgage Calculator | Debt Free Credit Card Debt | Filing Bankruptcy
bri189a Posted September 9, 2005 Posted September 9, 2005 Drag it from the tool box on to the web form. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.