Search code examples
asp.netvb.netobjectdatasource

ObjectDataSource and inline code


I have an objectdatasource on my page with the following Select parameter

<SelectParameters>
     <asp:Parameter Name="application" DefaultValue="<% = Membership.ApplicationName %>"  Type="String" />
</SelectParameters>

The problem is that it is literally passing to the datasource the string <% = Membership.ApplicationName %> rather than it's value. I have also tried passing in other values such as <% = DateTime.Now %> and the same thing occurs.

I have tested on the same page the following code and it works as expected

<% For i As Integer = 1 To 5 Step 1%>
    <% Response.Write(Membership.ApplicationName)%>          
<% Next%>

Have I missed something very obvious or is perhaps what I am trying to do not possible? The odd thing is that I am sure this worked when I was working on this project a few weeks back.


Solution

  • I think I have answered my own question. After playing around and getting the error;

    Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.Parameter does not have a DataBinding event.
    

    I can see now that this is not possible. I have no idea why I thought I had done this in the past.

    Instead I now have a control on my page that contains the value to use for the parameter for my Objectdatasource.