I am trying to create a variable on an ASP page without using code behind. So I use the tags <% %> but when I try to pass a value into my variable using the <%# Eval(" ") %> It thinks the closing tag is the end of the first open tag. How do I use the
eval command to pass database fields within ASP code?
I am basically trying to store the value of the stock of an item into a variable and do if statments on it to determine if I should display "In Stock" or "Out of Stock" Here is the code I have so far...
<%
Dim InStock As Integer
InStock = <%# Eval("Stock")%>
%>
Ok so if I use the following code, I can't figure out how to then reference the ASP label from inside the code. I need to send the value of the variable to the label. Bah, this is so difficult when you only know java. It's like I am programming with 3
languages at once lol.
<%
Dim InStock As Integer
InStock = Eval("Stock")
Stock.Text = InStock
%>
<asp:Label ID="Stock" runat="server" ForeColor="#33CC33"></asp:Label><br />
After I modified that code a bit I got it to work. But now I need to also change the font color of the Label control from default green to red if it is out of stock. Here is what it looks like so far.
<asp:Label ID="Stock" runat="server" ForeColor="#33CC33" Text='<%# If(Eval("Stock")> 0, "In Stock", "Out of Stock")%>'></asp:Label>
78coolbreeze
Member
3 Points
27 Posts
Using Eval Statements within ASP.NET Code
Nov 16, 2012 07:16 PM|LINK
I am trying to create a variable on an ASP page without using code behind. So I use the tags <% %> but when I try to pass a value into my variable using the <%# Eval(" ") %> It thinks the closing tag is the end of the first open tag. How do I use the eval command to pass database fields within ASP code?
I am basically trying to store the value of the stock of an item into a variable and do if statments on it to determine if I should display "In Stock" or "Out of Stock" Here is the code I have so far...
<% Dim InStock As Integer InStock = <%# Eval("Stock")%> %>DarthSwian
Star
12771 Points
2361 Posts
Re: Using Eval Statements within ASP.NET Code
Nov 16, 2012 07:20 PM|LINK
First off you can't do <% %> inside an outer <% %> thos are meant to be script blocks, you don't need it again.
Storing the variable would simply be
<% Dim Instock as Integer = SOMEINT %>
Seek and ye shall find or http://lmgtfy.com/
78coolbreeze
Member
3 Points
27 Posts
Re: Using Eval Statements within ASP.NET Code
Nov 16, 2012 07:27 PM|LINK
Ok so if I use the following code, I can't figure out how to then reference the ASP label from inside the code. I need to send the value of the variable to the label. Bah, this is so difficult when you only know java. It's like I am programming with 3 languages at once lol.
<% Dim InStock As Integer InStock = Eval("Stock") Stock.Text = InStock %> <asp:Label ID="Stock" runat="server" ForeColor="#33CC33"></asp:Label><br />oned_gk
All-Star
31651 Points
6468 Posts
Re: Using Eval Statements within ASP.NET Code
Nov 16, 2012 07:37 PM|LINK
78coolbreeze
Member
3 Points
27 Posts
Re: Using Eval Statements within ASP.NET Code
Nov 16, 2012 07:57 PM|LINK
After I modified that code a bit I got it to work. But now I need to also change the font color of the Label control from default green to red if it is out of stock. Here is what it looks like so far.
<asp:Label ID="Stock" runat="server" ForeColor="#33CC33" Text='<%# If(Eval("Stock")> 0, "In Stock", "Out of Stock")%>'></asp:Label>oned_gk
All-Star
31651 Points
6468 Posts
Re: Using Eval Statements within ASP.NET Code
Nov 17, 2012 01:25 AM|LINK
78coolbreeze
Member
3 Points
27 Posts
Re: Using Eval Statements within ASP.NET Code
Nov 17, 2012 01:41 AM|LINK
I will if I can ever get all this to work lol. I am such a newb at html, asp and vb. I can't even manually open a connection in the vb behind code. ><