Actually, I get an error when I try this. I suspect it has something to
do with using a renderblock variable to set the attribute of a server
control.
Here's the exact code I use.
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table>
<% int width=1; for(int i=0; i<5; i++, width=i*10) {%>
<tr>
<td>Line <%=i%> </td>
<td><asp:TextBox runat="server"
Width="<%=width%>"></asp:TextBox></td>
<td>Width = <%=width%></td>
</tr>
<%}%>
</table>
</form>
</body>
</HTML>
and I get the following error message:
Parser Error Message: '<%=width%>' can not be parsed as a unit as there
are no numeric values in it. Examples of valid unit strings are '1px'
and '.5in'
As for code behind, I do most of my programming in code behind. I need
to use inline code in this situation cause I want to set the width of a
textbox which is embedded inside a datalist. Yes, I could always use
codebehind, to go through each row in my datalist once its databound and
then set the widths of the textbox. But I think this is simpler to do,
if it would work
Thanks.
Temo