I want add one more parameter i.e session["emp_no"] varible in NavigateUrl
How can i achieve this please help
<asp:HyperLink ID="lblJovid" runat="server" Class="link" NavigateUrl= '<%# Eval("pid", "frm_IAF.aspx?id={0}") %>' Text='<%# Bind("pid") %>' ></asp:HyperLink>
You can use string.Format for this:
NavigateUrl= '<%# string.Format("frm_IAF.aspx?id={0}¶m2={1}", Eval("pid"), Session["emp_no"]) %>'
Related
I have a grid view template column that is a glyphicon in a hyperlink control, I am trying to pass an ID value that is in the SQL datasource to a page like so :
<ItemTemplate>
<asp:HyperLink ID="hlResident" CssClass="glyphicon glyphicon-refresh" NavigateUrl="Resident/<%#= Eval("ID") %>" runat="server"></asp:HyperLink>
</ItemTemplate>
I get the error "The Server Tag is not well formed".
Try this way
<asp:HyperLink ID="hlResident" CssClass="glyphicon glyphicon-refresh" NavigateUrl='<%# "Resident/" + Eval("ID") %>' runat="server"></asp:HyperLink>
Here the change is how you bind it
NavigateUrl='<%# "Resident/" + Eval("ID") %>'
<%#= Eval("ID") %>
Should be:
<%# Eval("ID") %>
There are some different types for asp tags. The accepted answer Here is very thorough on the subject.
NavigateUrl="Resident/<%#= Eval("ID") %>"
should be NavigateUrl='Resident/<%# Eval("ID") %>'
I want to display data on a page dynamically from database.
I have added a news box and I am displaying events list in repeater from a database. Hyperlink and Marquee is also used. But hyperlink is not displayed properly.
The code is given below:
<asp:HyperLink ID = "HyperLink1" runat = "server" NavigateUrl = "/events/events.aspx?id=<%#Eval('event_id') %>">
<asp:Label ID = "Label1" runat = "server" text = '<%# Eval("event_title") %>' ></asp:Label></asp:HyperLink><br/>
ASP.NET HyperLink should be declared like this:
<asp:HyperLink
ID="HyperLink1"
runat="server"
NavigateUrl="/events/events.aspx?id=<%#Eval('event_id') %>"
Text='<%# Eval("event_title") %>' />
change your code as
<asp:HyperLink
ID="HyperLink1" runat=server
NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "event_id", "/events/events.aspx?id={0}") %>'>
<%# DataBinder.Eval(Container.DataItem, "event_title") %>'
</asp:HyperLink>
I am trying to concat a string inside the attribute. I get an error. I think that it is related to my Eval. Is there a proper way to concat strings, or is this just not possible. The problem I believe is where I set the NavigateUrl.
<asp:HyperLink ID="lb"
runat="server"
Text='<%#Eval("Key.Id") %>'
NavigateUrl='ViewItem.aspx?id=' + '<%# Eval("Key.Id") %>'/>
Short answer: NavigateUrl='<%# Eval("Key.Id", "ViewItem.aspx?id={0}") %>'
Longer explanation:
The problem in your code is that you are use data binding expression only for part of your web control attribute. You need to move everything inside the data binding expression.
First of all, a data binding expression is this:
<%# EXPRESSION %>
Basically the rule for using a data binding expression for a web control attribute is that the expression must be the only thing in the attribute:
<asp:HyperLink ID="lb" runat="server"
Text='<%# EXPRESSION %>'
NavigateUrl='<%# EXPRESSION %>' />
So your first attribute, Text, is correct. But your second attribute, NavigateUrl is not correct. Because you put ViewItem.aspx?id= as the value for the attribute, leaving + '<%# Eval("Key.Id") %>' outside any attribute but inside the control tag.
Here is the correct syntax:
<asp:HyperLink ID="lb" runat="server"
Text='<%# Eval("Key.Id") %>'
NavigateUrl='<%# Eval("Key.Id", "ViewItem.aspx?id={0}") %>'/>
Notice that we are using a format string as the second parameter for Eval(). This is equivalent to the following, more explicit, syntax:
<asp:HyperLink ID="lb" runat="server"
Text='<%# Eval("Key.Id") %>'
NavigateUrl='<%# String.Format("ViewItem.aspx?id={0}", Eval("Key.Id")) %>'/>
Here's what I do when I have something in a gridview like this:
<img src='<%# GetDisImageLink(Eval("Disabilities").ToString()) %>'
alt="Disabilities" />
[CS code-behind]
public string GetDisImageLink(string dis)
{
return "../../Content/Images/CardContactInfo/" +
(dis.Trim() == "Y" ? "DIS.png" : "Blank.png");
}
Try this instead:
<asp:HyperLink ID="lb" runat="server" Text='<%#Eval("Key.Id") %>' NavigateUrl='ViewItem.aspx?id=<%# Eval("Key.Id") %>'/>
You don't need to concatenate
Currently in my webpage i load images to the ListView object as follows...
<ContentTemplate>
<asp:ListView ID="ListView1" runat="server">
<layouttemplate>
<asp:PlaceHolder id="itemPlaceholder" runat="server" />
</layouttemplate>
<ItemTemplate>
<td>
<asp:Image ID="Image1" runat="server"
ImageUrl = '<%# DataBinder.Eval(Container.DataItem, "Image") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
Now, i would like to use a combination of a Generic Handler and the ListView object to serve the images into the ListView
...the generic handler call is like
~/Handlers/Image.ashx?img=
How could i combine both above to serve images?
I tried something like the following but it is not correct
<asp:Image ID="Image1" runat="server"
ImageUrl = ~/Handlers/Image.ashx?img= & '<%# DataBinder.Eval(Container.DataItem, "Image") %>' />
So what is the correct way?
Yes that is the correct way. Your syntax for binding the ImageUrl not correct though.
Try this one:
<asp:Image ID="Image1" runat="server" ImageUrl ='<%# "~/Handlers/Image.ashx?img=" + Eval("Image")%>' />
You might also use the ItemDataBound event to use code like this:
Image image1 = e.FindControl("Image1") as Image;
YourClass item = e.DataItem as YourClass;
image1.ImageUrl = String.Format("~/Handlers/Image.ashx?img={0}", item.Image")
Try this
<ItemTemplate>
<asp:Hyperlink runat= "server" Text='<%#DataBinder.Eval(Container.DataItem,"ProductName").ToString()%>' NavigateUrl='<%# "page.aspx?Name=" & DataBinder.Eval (Container.DataItem,"ProductName").tostring %>' ID="ProductName"/>
</ItemTemplate>
Hope it helps
Source : http://www.extremeexperts.com/Net/FAQ/PassingMulitpleParameterinURLLink.aspx
What is the syntax to concatenate text into a binding expression for an asp.net webpage (aspx).
For example if I had a hyperlink that was being bound like this:
<asp:HyperLink id="lnkID" NavigateUrl='<%# Bind("Link") %>' Target="_blank"
Text="View" runat="server"/>
How do you change, say, the Text to concatenate a bound value with a string? Variations like this aren't quite right.
Text='<%# Bind("ID") + " View" %>'
neither does
Text='<%# String.Concat(Bind("ID"), " View") %>'
Use Eval instead.
Text='<%# Eval("ID", "{0} View") %>'
Eval is also better if the value is not going to be updated, where Bind allows two way data binding.
You can also place the "concatenation" in the text portion of a tag if using a template field:
<asp:TemplateField HeaderText="Name" SortExpression="sortName">
<ItemTemplate>
<asp:LinkButton ID="lbName" runat="server" OnClick="lbName_Click" CommandArgument='<%# Eval("ID") %>'>
<%--Enter any text / eval bindind you want between the tags--%>
<%# Eval("Name") %> (<%# Eval("ID") %>)
</asp:LinkButton>
</ItemTemplate>
This results in output like:
Name (ID)
inside of the template column.
I have used String.Format("{0}{1}"... before to good effect.
You could use the following:
CommandArgument='<%#String.Format("{0}|{1}", Eval("ArgZero"), Eval("ArgOn"))%>'