Sunday, March 11, 2012

DataItem access in ascx

I am currently building an ecommerce site using aspx, vbscript, & sql.
In my productlist control containing a datalist I am trying to use an ifstatement to determine if products are from a certain supplier... andif they are; display a phone number to call for pricing rather than theprice, since this particular supplier doesnt allow pricing of theirproducts online.
This is what I have now:
<%
Dim objConn
objConn = Server.CreateObject("ADODB.Connection")
Dim strConnect
strConnect = ConfigurationSettings.AppSettings("ConnectionString")
Dim supplier
objConn.Open(strConnect)
supplier = objConn.Execute("Select SupplierID From Product")
If supplier = "C" Then
Response.Write("Call 1-800-POO-STAIN")
Else
Response.Write(" Sug. Retail:")
DataBinder.Eval(Container.DataItem, "Price")
End IF
objConn.Close
objConn = Nothing
%>
This code gives me the following error message:
The component 'ADODB.Connection' cannot be created. Apartment threaded components can only be created on pages with an <%@. Page aspcompat=true %> page directive

Can anybody help me get this working?
I haven't worked with VBScript for acouple years now and I'm a little rusty.
Any help would be greatly appreciated

What you have is Classic ASP code. You should change the extension to ASP, or convert the code to use VB.NET and the ADO.NET components.
Alternately, add this to the top of the page:
<%@. Page aspcompat=true %>
|||

The problem is I am using this in an ascx control. aspcompat is not supported by the 'control' directive.

Any other suggestions?

|||the page that will hold the ascx needs to have the aspcompat attribute.