Two way databinding using variable names

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?
 
B

Brock Allen

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top