473,409 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

ASPX C#.NET Equivilent to ASP VBA Code

I have some legacy ASP code that looks like this:

<%
if not (Rs.EOF) then
i=0
do while not Rs.EOF
i=i+1
PaymentItemName = Rs("PaymentItemName")
PaymentItemCode = Rs("PaymentItemCode")
%>
<tr>
<td><input type="text" name="PaymentItemName_N<%=i%>" size="20"
value="<%=PaymentItemName%>" style="background:#D5FFC8"
<%=Use_permission%>></td>
<td></td>
<td><input type="text" name="PaymentItemCode_N<%=i%>" size="10"
value="<%=PaymentItemCode%>" <%=Use_permission%>></td>
</tr>
<%
loop
end if
%>

What would be the C#.NET equivilent?

I tried (snipped for ease of reading):

<td><input type="text" name="PaymentItemName_N<%=i;%>" size="20"
value="<%=PaymentItemName;%>" style="background:#D5FFC8"
<%=Use_permission;%>></td>

and I just get errors.
Mar 30 '07 #1
2 1674
We don't need to use the semi-colon in a data binding expression as you
show. Now you should also submit he following search term to google or
whatever...

eval data binder

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
"Andrew Hayes" <An*********@discussions.microsoft.comwrote in message
news:BB**********************************@microsof t.com...
>I have some legacy ASP code that looks like this:

<%
if not (Rs.EOF) then
i=0
do while not Rs.EOF
i=i+1
PaymentItemName = Rs("PaymentItemName")
PaymentItemCode = Rs("PaymentItemCode")
%>
<tr>
<td><input type="text" name="PaymentItemName_N<%=i%>" size="20"
value="<%=PaymentItemName%>" style="background:#D5FFC8"
<%=Use_permission%>></td>
<td></td>
<td><input type="text" name="PaymentItemCode_N<%=i%>" size="10"
value="<%=PaymentItemCode%>" <%=Use_permission%>></td>
</tr>
<%
loop
end if
%>

What would be the C#.NET equivilent?

I tried (snipped for ease of reading):

<td><input type="text" name="PaymentItemName_N<%=i;%>" size="20"
value="<%=PaymentItemName;%>" style="background:#D5FFC8"
<%=Use_permission;%>></td>

and I just get errors.

Mar 30 '07 #2
Thanks for the pointer.

I trawled through the results looking for how to use the <%# ... %code to
set the property of a control, and after much trial and error this is what
I've found:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET 2.0 Projects</title>

<script language="C#" runat="server">
String[] urlArray = {"http://localhost/Corporate",
"http://localhost/FormViewData/employees.aspx",
"http://localhost/Membership",
"http://localhost/TestASP",
"http://localhost/Worklist"};

String[] textArray = {"Corporate Website",
"FormViewData",
"Membership",
"TestASP",
"Worklist"};

Int32 count;
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>ASP.NET 2.0 Projects</h1>
<%
for (count = 0; count < urlArray.Length; count++)
{
Page.DataBind();
%>
<br />
<asp:HyperLink runat="server" NavigateUrl="<%# urlArray[count]
%>"><%=textArray[count]%></asp:HyperLink><br />
<%
}
%>
</div>
</form>
</body>
</html>

Only by using <%# urlArray[count] %can I set the NavigateURL property of
the HyperLink control. And only by calling Page.DataBind() on every iteration
of the loop can I ensure that the urlArray[count] variable has the correct
value. If I don't, then it always returns urlArray[0].

I can also use the older ASP syntax <%=textArray[count]%>, but only when not
assigning it to a property. Using NavigateURL="<%=urlArray[count]%>" will set
the property to the literal string.

Why this is the case puzzles me. In older ASP code, the <%=...%syntax is
often used to assign values to button text, dropdown list items, and control
names, but while the syntax is supported in ASPX, it doesn't work the same
way for control property assignments, meaning you have to rewrite all the ASP
code.

So this ASP code:

<td><input type="text" name="PaymentItemName_N<%=i%>" size="20"
value="<%=PaymentItemName%>" style="background:#D5FFC8"
<%=Use_permission%>></td>

Becomes this ASPX code:

<td><input type="text" name="<%# PaymentItemControlName(i) %>" size="20"
value="<%# PaymentItemName %>" style="background:#D5FFC8"
<%=Use_permission%>></td>

Where PaymentItemControlName() returns a String which is a concatenation of
"PaymentItemName_N" and i, PaymentItemName has to be an eval as it's assigned
to a property, but Use_permission doesn't as it's a string literal.

Apr 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Darren | last post by:
Hi. I have a javascript menu system which uses the "elementFromPoint" function. However Netscape/Mozilla doesn't recognise this function. Does it have an equivilent? Thanks -- Darren
2
by: John Galt | last post by:
I was looking at a VB.NET program that is passing strings to method calls using ByVal. I was wondering if this is for a reason and, if so, should a C# conversion of code samples from VB.NET also...
4
by: trint | last post by:
I can't find the followings equivilent: flashPlayer.Movie = Application.StartupPath + @"/Cooler2.swf"; flashPlayer.FSCommand +=new...
2
by: Steve1 via DotNetMonster.com | last post by:
Hi all, I'm producing a data conversion app in C#. I have the code already written in VB6. I would to know if anyone knows of any links that shows the VB6 function/syntax equivilent in C#? ...
1
by: Ryan Ternier | last post by:
I'm trying to find an equivilent function to VB's DatePart function. I have a Year, Month, the Day of week (Sunday, monday etc.) and the week (week 1, week 2) and I need to find the date of that...
0
by: nic | last post by:
Hi, I need to get the equivilent of Response.Redirect (~/mypage.aspx) for a dynamic javascript function. Essentially I am writing the javascript on the non-code behind page and need to inject the...
6
by: dkode8 | last post by:
Hello, I am creating an application that uses impersonation to log a user into our domain and then show them the contents of their network share where they store their files. I have all the...
1
by: Andy Fish | last post by:
Hi, In my aspx web application, I am generating a list of items in a menu down the left-hand side. Different items in the list may have different controls in, and this is data-driven at runtime....
4
by: MikeLing | last post by:
Hi, String.IndexOf is case sensitive so I need to covert to lower before testing the string contains a given string. In VB this is: Instr(Lcase(StringToTest, "StringToCheckFor")) What is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.