I've made a new DetailsHelper CodeSmith template to help generate those boring and tedious details forms. I like to place the details in a repeater. This makes it easy to bind, and while I usually only bind one record to it, in the future that could change. Here's the first cut:
<%@ CodeTemplate Language="C#" TargetLanguage="ASP.NET" Description="Template for ASPX Form generation." %>
<%@ Property Name="TableName" Type="SchemaExplorer.TableSchema" Category="Data" Description="Provide the table for which the dataentry form has to be created." %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import Namespace="System.Data" %>
<asp:Panel ID="pnlDetails" Runat="server">
<asp:Repeater ID="rptDetails" Runat="server">
<HeaderTemplate><table width="100%" cellpadding="3" cellspacing="0" border="0"></HeaderTemplate>
<ItemTemplate><%
int i = 1;
foreach(ColumnSchema cs in TableName.Columns)
{
Response.Write(GetColumnASPX(cs,i));
i *= -1;
}
%>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
</asp:Panel>
<script runat="template">
public string GetColumnASPX(ColumnSchema cs, int i)
{
string retVal = "";
if(!cs.IsPrimaryKeyMember)
{
retVal += "\n\t<tr";
if(i==1)
retVal += " class=\"alt\"";
retVal += ">\n\t\t<td align=\"right\">" + cs.Name + "</td>";
retVal += "\n\t\t<td><%# DataBinder.Eval(Container.DataItem, \"" + cs.Name + "\") %></td>";
retVal += "</td>\n\t</tr>";
}
return retVal;
}
</script>