I want to pass two values with a navigate URL using Eval method, but it doesn't take more than one value.
Here is my code
<asp:HyperLink ID="HyperLink1" runat ="server" Text='<%#Eval("ReportTitle") %>' NavigateUrl='<%# Eval("ReportId","GroupId","~/Groups/ReportPage.aspx?ReportId={0}&Group={1}")%>' > </asp:HyperLink>
But I have this error(Error3 No overload for method 'Eval' takes 3 arguments)
so how can i do what i want to?
Thanks
Try this:
<%# String.Format("~/Groups/ReportPage.aspx?ReportId={0}&Group={1}", DataBinder.Eval(Container.DataItem, "ReportId"), DataBinder.Eval(Container.DataItem, "GroupId"))%>
You might want to review this.
One way is:
<%# String.Format("{0} - {1}", Eval("Name1"), Eval("Name2")) %>
Related
My question is how can I put this
<%# Eval("about")%>
into this function
<% Utils.UserUtils.showNiceDesc(here goes string - "about") %>
In asp.net webforms?
Regards
This does what you want; it passes the result of Eval to a method.
<%# Utils.UserUtils.showNiceDesc(Eval("about")) %>
Use combination of single and double quotes.
'<% Utils.UserUtils.showNiceDesc(Eval("about")) %>'
Use like below
You should use ToString() function.
'<% Utils.UserUtils.showNiceDesc(Eval("about").ToString()) %>'
<tag text='<%# Utils.UserUtils.showNiceDesc(((YourDataItemClass)Container.DataItem).about) %>' />
or
<tag text='<%# Utils.UserUtils.showNiceDesc(DataBinder.Eval("about")) %>' />
Reference: http://msdn.microsoft.com/en-us/library/bda9bbfx(v=vs.100).aspx
I've got a:
Data repeater
Control in the repeater
And I'd like to put some values into the controls. At the moment I have a control in it as:
<asp:Repeater runat="server" ID="ArchiveEntryRepeater">
snip
<asp:HyperLink ID="HyperLink1" ToolTip="Comment on Some Entry Title Here" runat="server" NavigateUrl="~/Blog/7/How-to-know-when-this/Comments">
<strong><%# DataBinder.Eval(Container.DataItem, "Comments")%></strong> Comments
</asp:HyperLink>
snip
</asp:Repeater>
Which works fine, but I want to put
<%# DataBinder.Eval(Container.DataItem, "Title")%>
Into the NavigateURL property of the Hyperlink. Just putting it in doesn't seem to work!
Try enclosing your NavigateURL in apostrophes instead of double quotes to not confuse the ASP.NET parser:
<asp:HyperLink runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "Title")%>' [...]>[...]</asp:HyperLink>
This might be your issue.
You can always bind on the back end using the event itemdatabound. It has some advantages especially where the data is not a neat view or needs some type of major manipulation.
Another option would be to loose the control and replace it with an html anchor control like this:
<asp:Repeater>
<ItemTemplate>
<a id="HyperLink1" title="Comment on Some Entry Title Here" href='<%# DataBinder.Eval(Container.DataItem, "Title")%>'
style="font-weight: bold">'<%# DataBinder.Eval(Container.DataItem, "Comments")%>'</a>
</ItemTemplate>
</asp:Repeater>
Once the server renders a hyperlink to the client there is generally no reason to have it "runat='server'" . The purpose is to navigate to another page so the overhead of using an asp:HyperLink vs. an nchor is wasted.
How do I display the value of a resource without a ASP.NET control, i.e. I want to avoid this:
<asp:Label text="<%$ Resources: Messages, ThankYouLabel %>" id="label1" runat="server" />
Instead I would prefer to do just this in my .aspx pages:
<%$ Resources: Messages, ThankYouLabel %>
... but I can’t, a parser error is thrown:
Literal expressions like '<%$ Resources: Messages, ThankYouLabel %>' are not allowed.
Use <asp:Literal runat="server" Text="<%$ Resources: Messages, ThankYouLabel %>" /> instead.
Use HttpContext.GetGlobalResourceObject instead:
<asp:Label text='<%= GetGlobalResourceObject("Messages", "ThankYouLabel") %>'
id="label1"
runat="server" />
It's not possible. you have to use atleast Literal, Another option is to use GetGlobalResurceObject, so that you can use directly in a page.
<%= GetGlobalResourceObject("Messages", "ThankYouLabel")%>
In code behind You can Use
`GetLocalResourceObject("YourKeyInLocalResource")`
and also
`GetGlobalResourceObject("GlobalResourceFileName", "YourResourceKey")`
and then use a simple aspnet variable in your Asp.net Markup like <%= Resourcevalue %>
The you can assign your resource value to your Aspnet Variable like
Resourcevalue = GetGlobalResourceObject("GlobalResourceFileName", "YourResourceKey").ToString();
Another method is :-
<asp:Label text='<%= Resources.Messages.ThankYouLabel %>'
id="label1"
runat="server" />
how would you go about adding logic to a datagrid item template? In my datagrid, i want to add a logic to it. that is, if the result for the data equals to "Yes", an "asp:label" control will be displayed; otherwise a "asp:imagebutton" control will be shown
<ItemTemplate1>
<% if DataBinder.Eval(Container.DataItem, "boflag").equals("Yes") then%>
<asp:Label id="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"boflag")%>'></asp:Label>
<% Else %>
<asp:imagebutton id="imgBtnUpdate" runat="server" NAME="Imagebutton3"
ImageUrl="no.gif"></asp:imagebutton>
<% end if %>
</ItemTemplate>
However, "<% if DataBinder.Eval(Container.DataItem,
"boflag").equals("Yes") then%> " this is not valid.
So, how can i get the data to compare the value.
Thank you
You should implement the items Data Bound Event in the code behind. Then show/hide/populate the controls there.
One other option you can do is to use a ternary operator to evaluate the boflag field and output accordingly. For example:
<%# DataBinder.Eval(Container.DataItem, "boflag").equals("Yes") ? DataBinder.Eval(Container.DataItem,"boflag") : "<input type=\"image\" src=\"\" />" %>
I'm not sure that you could add server controls through this method, but you could certainly add conditional HTML.
Basically I would like to find a way to ddo something like:
<asp:Label ID="lID" runat="server" AssociatedControlID="txtId" Text="<%# MyProperty %>"></asp:Label>
I know I could set it from code behind (writing lId.Text = MyProperty), but I'd prefer doing it in the markup and I just can't seem to find the solution.
(MyProperty is a string property)
cheers
You can do
<asp:Label runat="server" Text='<%# MyProperty %>' />
And then a Page.DataBind() in the codebehind.
Code expressions are an option as well. These can be used inside of quotes in ASP tags, unlike standard <%= %> tags.
The general syntax is:
<%$ resources: ResourceKey %>
There is a built-in expression for appSettings:
<%$ appSettings: AppSettingsKey %>
More info on this here: http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx
Leave the markup as is and make a call to Page.DataBind(); in your code behind.
<asp:Label id="lID" runat="server"><%= MyProperty %></asp:Label>
since asp.net tags do not allow <% %> constructs, you cannot use Text="<%= MyProperty %>".
<div> <%=MyProperty"%></div>
Call lID.Databind() from code-behind
When you use <%# MyProperty %> declaration you need to databind it, but when using <%= MyProperty %> you don't (which is similar to just writing Response.Write(MyProperty).
You can do this:
<asp:Label ID="lblCurrentTime" runat="server">
Last update: <%=DateTime.Now.ToString()%>
</asp:Label>