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>
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 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"]) %>'
I have a hyperlink inside a repeater control for the list of pdf. I want to set a download counter on each click on each hyperlink. The FileName must be a parameter. My code is basically like below. There is also code that calls stored procedure and bind it to the repeater on page_load.
<asp:Repeater ID="rptPDF" runat="server">
<ItemTemplate>
<div class="repeaterResources">
<b><%# Eval("Name") %></b><br />
<b>Description</b> <%# Eval("Description") %><br />
<asp:HyperLink ID="HyperLink2" runat="server" class="downloadLink" NavigateUrl='<%# "~/PDF/" & Eval("Filename") %>' Target="_blank">Download</asp:HyperLink><br /><br />
</div>
</ItemTemplate>
</asp:Repeater>
The mystery bit is how to get a button click event from here. Thanks.
You can use the OnCommand event and set the CommandArgument attribute with a value using
<%# Eval('myvalue') %>.
MSDN has an example minus the repeater: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.oncommand.aspx
Sample:
<asp:Repeater ID="repeater" runat="server">
<ItemTemplate>
<asp:LinkButton runat="server" ID="button1" OnCommand="button1_command" CommandArgument='<%# Eval("myvalue") %>' />
</ItemTemplate>
</asp:Repeater>
I would like to have a repeater control bound to method and display the result as a list of linkbuttons, but I can't get by head around it. This is what I've tried:
In the asp page I have:
<asp:Repeater ID="resultCountRepeater" runat="server" Visible="false" >
<ItemTemplate>
<asp:LinkButton ID="userResultCount" runat="server" OnClick="userResultCount_Click" Text="<%# DataBinder.Eval(Container.DataItem,"Text") %>" >
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
And in the code behind:
List<ListItem> resultCountList = new List<ListItem>();
foreach (ISearchEngine oneEng in engines)
{
ListItem item = new ListItem();
item.Text = oneEng.ObectName();
item.Value = Convert.ToString(oneEng.PageCount(searchWords, townId));
resultCountList.Add(item);
}
resultCountRepeater.DataSource = resultCountList;
resultCountRepeater.DataBind();
Unfortunately this is giving me a compile error: The server tag is not well formed.
Any ideas what it wrong?
Thanks
Use single quotes to dynamically set properties.
<asp:LinkButton ID="userResultCount" runat="server" OnClick="userResultCount_Click" Text="<%# DataBinder.Eval(Container.DataItem,"Text") %>" ></asp:LinkButton>
Should be
<asp:LinkButton ID="userResultCount" runat="server" OnClick="userResultCount_Click" Text='<%# DataBinder.Eval(Container.DataItem,"Text") %>' ></asp:LinkButton>
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