i'm trying to bind dataitem in GridView like that:
<%# DataBinder.Eval(Container, "DataItem.Project No.") %>
and getting the error:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Project No'.
the field is Project No. (with a dot .).
how can i bind that field?
try this : [] to indicatethat it is a column name.
<%# DataBinder.Eval(Container, "DataItem.[Project No.]") %>
<%# Eval("Project No.") %>
note that your datatable/dataset should have Project No. exactly to work
Update
100% Working & Tested
<%#DataBinder.GetPropertyValue(Container.DataItem,"Project No.") %>
Related
When I loop through my data in c# I have to use the below to get the value:
foreach (var item in documentQuery)
{
string value = item.getproperty("title");
//value = "hello world"
}
But if I want to bind the results to an asp:repeater in an ASPX page how would I call this same getproperty method in the ItemTemplate? Because if I just go <%# Eval("title") %> it gives an error...
Eval() is a shortcut to simplify binding. To do something more complex, you won't be able to use it.
I think you need to do something like:
<%# Container.DataItem.getproperty("title")) %>
Or you might have to cast Container.DataItem to your specific type of item:
<%# (Container.DataItem as XXXXXXX).getproperty("title")) %>
where XXXXXXX is whatever the type your item is.
I am trying to use Web.Router and I am trying to set it in a hyperlink where some variables need to be binded from a dataTable. Also, this link is a part of a Gridview:-
<%# Eval("title")) %>
But I get error: Server Tag not well formed. What's wrong with the syntax?
Try changing
<%# Eval("title")) %>
To this
<%# Eval("title")) %>
You put a double quot instead of single quot
I have this databinding expression:
<%# (Boolean.Parse(DataBinder.Eval(Container.DataItem, "HasFoo").ToString())) ? "Yes" : "No" %>
I want to use an asp.net resource binding tag for "yes" and "no," so that in other languages I can use the correct language (I know, I know, mostly everyone uses yes and no but this is just an example).
I've tried putting in
"<%$ Resources: General, Yes %>"
It is in an item template:
<ItemTemplate>
<%# (Boolean.Parse(DataBinder.Eval(Container.DataItem, "HasFoo").ToString())) ? "Yes" : "No" %>
</ItemTemplate>
But it seems I can't do that inside the databinding expression. Anyone have any ideas other than loading these resources at page_init and then hiding them in a serverside hidden panel?
You can retrieve any static Resource value using:
GetLocalResourceObject:
<%= HttpContext.GetLocalResourceObject(virtualPath, resourceKey, CultureInfo) %>
GetGlobalResourceObject:
<%= HttpContext.GetGlobalResourceObject(classKey, resourceKey, CultureInfo) %>
Take a look here for more information: How to: Retrieve Resource Values Programmatically
I'm trying to set the PropertiesList of a node as the DataSource for my repeater.
rptDistributors.DataSource = node.PropertiesAsList;
rptDistributors.DataBind();
And in my repeater I try to get the umbDistributorCountry.
<asp:Repeater ID="rptDistributors" runat="server">
<%# Eval("umbDistributorCountry") %>
</asp:Repeater>
However I run into problems because it doesn't know any of the properties.
DataBinding: 'umbraco.NodeFactory.Property' does not contain a property with the name 'umbDistributorCountry'.
The content of the list looks like the following:
Any ideas?
Thanks,
Thomas
The clue is in the error ...
DataBinding: 'umbraco.NodeFactory.Property' does not contain a property with the name 'umbDistributorCountry'.
umbDistributorCountry is not a .NET property, but the value of the property called Alias. An Umbraco property contains the three .NET properties in your screenshot, so you only have access to these ...
<%# Eval("Alias") %>
<%# Eval("Value") %>
<%# Eval("Version") %>
Assuming you want to show all the Umbraco properties of that particular distributor (which is stored in node, I guess), you would need something like this ....
<asp:Repeater ID="rptDistributors" runat="server">
<ItemTemplate>
<%# Eval("Alias") %> : <%# Eval("Value") %> <br />
</ItemTemplate>
</asp:Repeater>
In have a list of objects bound to a ListView that is used to make a nice list of these items. In this ListView I have 1 column that shoud have a specific condition to display a specific string. Is this possible using inline code or should I get a workaround using the codebehind?
This is what I would like to do:
<% if (((Recipe)Container.DataItem).Status == RecipesModel.REJECTED) { %>
Something goes here
<% } %>
But this returns this exception:
The name 'Container' does not exist in the current context
EDIT: this code is used inside <ItemTemplate>
EDIT 2: I found myself using the following code for this problem:
<asp:PlaceHolder id="place_public" runat="server" Visible='<%# ((Recipe)Container.DataItem).Status == RecipesModel.VALIDATED %>'>
Something here
</asp:PlaceHolder>
you cannot use Container.DataItem outside of data binding context
try something like
<%# Container.DataItem ... %>
eg:
<%# ((String)Container.DataItem).ToUpper() == "test" ? "IsTest" : "NotTest" %>
You may want to import the namespace of the container class in your .aspx page.
for example:
<%# Import Namespace="Container Class namespace" %>
It looks like you are trying to use the Container object outside of its scope. Can you post the rest of the code so we can see what is happening on the page?