Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

Posted
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.
Posted

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

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...