Regedek
asked on
Need help migrating If..Then.. Else statement from Classic ASP to .NET
How would I replicate the following Classic ASP code in VB.NET?
<% If isNull(rs("client_website" )) OR rs("client_website") = "" Then %>
<br />
<% Else %>
<a target="_blank" href="<%=rs("client_websit e")%>">vie w website</a><br />
<% End If %>
<% If isNull(rs("client_website"
<br />
<% Else %>
<a target="_blank" href="<%=rs("client_websit
<% End If %>
ASKER
I'm VERY new to .NET (Only my second day of exposure)... So I have some additional questions...
To include a literal control would the vb code behind look something like this?
Dim Literal1 As Object
Literal1 = New Project1.Class1
Or am I doing this incorrectly?
Another question...
Can I still use isNull - or should I use IsDBNull (for instance):
If IsDBNull("client_website") OR ("client_website") = "" Then
And lastly...
What would the HTML markup look like - could/would I use an asp label to display it?
<asp:label id="Literal1" runat="server"></asp:label >
Not sure if it will help to answer my question, but I'm including the odbc connection code just in case:
Dim connStr As String = ConfigurationManager.AppSe ttings("DS N1").ToStr ing()
Dim dbconn As New OdbcConnection(connStr)
Sub Page_Load()
Select Request("ToDo")
'***********
Case "ViewEvent"
'***********
Dim sql As Object
Dim dbcomm As Object
Dim dbread As Object
dbconn.Open()
sql = "SELECT * FROM Events WHERE id=" & Int(Request("eventid"))
dbcomm = New OdbcCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
ViewMyEvent.DataSource = dbread
ViewMyEvent.DataBind()
dbread.Close()
dbconn.Close()
Any help is appreciated... Thanks in advance.
To include a literal control would the vb code behind look something like this?
Dim Literal1 As Object
Literal1 = New Project1.Class1
Or am I doing this incorrectly?
Another question...
Can I still use isNull - or should I use IsDBNull (for instance):
If IsDBNull("client_website")
And lastly...
What would the HTML markup look like - could/would I use an asp label to display it?
<asp:label id="Literal1" runat="server"></asp:label
Not sure if it will help to answer my question, but I'm including the odbc connection code just in case:
Dim connStr As String = ConfigurationManager.AppSe
Dim dbconn As New OdbcConnection(connStr)
Sub Page_Load()
Select Request("ToDo")
'***********
Case "ViewEvent"
'***********
Dim sql As Object
Dim dbcomm As Object
Dim dbread As Object
dbconn.Open()
sql = "SELECT * FROM Events WHERE id=" & Int(Request("eventid"))
dbcomm = New OdbcCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
ViewMyEvent.DataSource = dbread
ViewMyEvent.DataBind()
dbread.Close()
dbconn.Close()
Any help is appreciated... Thanks in advance.
You can literally just declare an <asp:literal in your .aspx file.
<asp:Literal ID="Literal1" runat="server"></asp:Liter al>
Or you can do in your code behind
Dim literal1 As New Literal()
Controls.Add(literal1)
But it's much easier to control the placement of your literal the first way.
<asp:Literal ID="Literal1" runat="server"></asp:Liter
Or you can do in your code behind
Dim literal1 As New Literal()
Controls.Add(literal1)
But it's much easier to control the placement of your literal the first way.
isdbnull is ONLY used for columns in a row from a table you got back from the database, not for other objects.
ASKER
These are in fact columns being pulled from a database table, so I should swap isNull with isDBNull correct?
Correct.
ASKER
I apologize for my high level of .NET ignorance here... Please bear with me...
I made the changes you suggested. When I attempt to load the page however, I get the following error:
'rs' is not declared. It may be inaccessible due to its protection level.
So my next question is: What do I use in place of rs() in .NET (as below)?
If IsDBNull(rs("client_website")) Or rs("client_website") = "" Then
literal1.Text = "<br/>"
Else
literal1.Text = "<a target='_blank' href='<" + rs("client_website") + ">'>view website</a><br />"
End If
If I remove the "rs" from the above code and just leave the field names - the page will load up, but the asp:literal does not display for those records in which the client_website field contains data.
I made the changes you suggested. When I attempt to load the page however, I get the following error:
'rs' is not declared. It may be inaccessible due to its protection level.
So my next question is: What do I use in place of rs() in .NET (as below)?
If IsDBNull(rs("client_website")) Or rs("client_website") = "" Then
literal1.Text = "<br/>"
Else
literal1.Text = "<a target='_blank' href='<" + rs("client_website") + ">'>view website</a><br />"
End If
If I remove the "rs" from the above code and just leave the field names - the page will load up, but the asp:literal does not display for those records in which the client_website field contains data.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked perfectly!
Thanks for your help... Much appreciated!
Thanks for your help... Much appreciated!
My pleasure, have fun with .NET.
In the code behind, do
If isNull(rs("client_website"
literal1.Text = "<br/>"
else
literal1.text = "<a target='_blank' href='<" + rs("client_website") + ">'>view website</a><br />"
end if