Two way databinding using variable names

  • Thread starter Thread starter cab0san
  • Start date Start date
C

cab0san

Is it possible to use a publicly scoped string vaiable as an argument
to the bind method?

A normal bind method works like this:

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CustID")
%>'></asp:TextBox>

I get an error when I try this:

Public strCustIDFieldName as String="CustID"

<asp:TextBox ID="Text1" runat="server" Text='<%#
Bind(strCustIDFieldName) %>'></asp:TextBox>

The error is:

"A call to Bind was not well formatted"

The documentation says I can use any publicly scoped code,and it works
fine with the eval function.

Are literals the only thing allowed?
 
You can do this:

<script runat="server">
string GetPropName()
{
return "SomePropName";
}
</script>

<asp:Repeater runat="server" ID="_rep">
<ItemTemplate>
<%# Eval(GetPropName()) %><br />
</ItemTemplate>
</asp:Repeater>

-Brock
http://staff.develop.com/ballen
 
Back
Top