Currently my Gridview hyperlink is passing one parameter in URL as show below
<asp:HyperLink ID="hlnkREQUEST_ID" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.REQUEST_ID") %>'
NavigateUrl='<%# "~/StudentPages/viewREQUEST_ID_page.aspx?REQUEST_ID="+DataBinder.Eval(Container, "DataItem.REQUEST_ID")%>' >
Now, in the same hyperlink I need to pass another parameter which I am adding like this:
<asp:HyperLink ID="hlnkREQUEST_ID" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.REQUEST_ID") %>'
NavigateUrl='<%# "~/StudentPages/viewREQUEST_ID_page.aspx?REQUEST_ID="+DataBinder.Eval(Container, "DataItem.REQUEST_ID") & REQUESTER="+DataBinder.Eval(Container, "DataItem.REQUESTER")%>'>
but this is causing an error
"REQUESTER" does not exist in current context
What's wrong here?
You need to make changes:
<asp:HyperLink ID="hlnkREQUEST_ID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.REQUEST_ID") %>' NavigateUrl='<%# "~/StudentPages/viewREQUEST_ID_page.aspx?REQUEST_ID="+DataBinder.Eval(Container, "DataItem.REQUEST_ID") + "&REQUESTER="+DataBinder.Eval(Container, "DataItem.REQUESTER")%>'>
Related
What is the correct syntax to the NavigateURL attribute of asp:HyperLink?
Error came when I used double quote characters.
(Eg:-Number of "visits accessing our community" health physiotherapy services )
<RAD:GridTemplateColumn HeaderText="KPI" DataField="DisplayName" UniqueName="KPIName" GroupByExpression="DisplayName Group By DisplayName">
<ItemTemplate>
<asp:Label Text='<%# Eval("DisplayName") %>' ID="lblKPI" runat="server" Visible="false" />
<asp:HyperLink runat="server" ID="lnkKpi" rel='<%# Eval("DisplayName") %>' Text='<%# Eval("DisplayName") %>' NavigateUrl='<%# Eval("KPIID","~/Authorised/PerformanceManagement/PerformanceManagement.aspx?Kpi={0}") %>' Target="_blank"></asp:HyperLink>
</ItemTemplate>
</RAD:GridTemplateColumn>
Result
How to handle the error ?
Use HtmlEncode for the values
Text='<%# HttpUtility.HtmlEncode(Eval("DisplayName")) %>'
Or
NavigateUrl='<%# "~/Authorised/PerformanceManagement/PerformanceManagement.aspx?Kpi=" + HttpUtility.HtmlEncode(Eval("DisplayName")) %>'
You can do it by creating a URL in the code behind file.
See Dynamically set a hyperlink control's NavigateUrl property inline.
How to manage Hyperlinks base on AttachmentID, In Inside link button there is two hyperlink to manage, If AttachmentID is "NA" Then Hyperlink ID one should visible else Hyperlink ID two should visible. I tried lots into google like this code not able to find. I tried using ItemCommand and ItemDataBound but did not understand this concept. The main concept to do this manage target="_blank".
Below is my Repeater Code.
<asp:Repeater ID="Repeater_News1" runat="server" OnItemDataBound="Repeater_News1_ItemDataBound">
<ItemTemplate>
<asp:Image ID="Image2" runat="server" class="pull-left img-responsive" ImageUrl='<%# Bind("ImageName", "~/images/news_images/{0}") %>' />
<asp:LinkButton ID="lnkbtn_check" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Attachmentid") %>'>
<a href='<%# DataBinder.Eval(Container.DataItem, "Attachment")%>' id="one"
target="_blank">
<%# DataBinder.Eval(Container, "DataItem.Heading")%></a>
<a href='<%# DataBinder.Eval(Container.DataItem, "Attachment")%>' id="two">
<%# DataBinder.Eval(Container, "DataItem.Heading")%></a>
</asp:LinkButton>
</h4>
<p>
<%# DataBinder.Eval(Container, "DataItem.SmallDescription")%></p>
</ItemTemplate>
</asp:Repeater>
Use this in your repeater:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Attachment") %>' Visible='<%# Eval("AttachmentID").ToString() != "NA" %>' Text='<%# Eval("DataItem.Heading") %>' Target="_blank" />
You can set the Visibility with an if statement in the HyperLink itself: Visible='<%# Eval("AttachmentID").ToString() != "NA" %>'
UPDATE
You can also check the AttachmentID for IsNullOrEmpty and show the correct hyperlink.
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Attachment") %>' Visible='<%# string.IsNullOrEmpty(Eval("AttachmentID").ToString()) %>' Text='<%# Eval("DataItem.Heading") %>' Target="_blank" />
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# Eval("Attachment") %>' Visible='<%# !string.IsNullOrEmpty(Eval("AttachmentID").ToString()) %>' Text='<%# Eval("DataItem.Heading") %>' Target="_self" />
I am getting this ~/Data/TestCopy.pdf for my Documents in the GridView but I am trying to get only the filename without the directory from SQL database. Does anyone know how to achieve this?
Thanks!
<asp:TemplateField HeaderText="Documents " SortExpression="filePath">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("filePath") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Target="_blank" runat="server" Text='<%# Bind("filePath") %>'
NavigateUrl='<%# Eval("filePath") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
The simplest way is, just add the Reference to System.IO and use Path class to get only the file name, little change in your code,
<asp:TemplateField HeaderText="Documents " SortExpression="filePath">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Path.GetFileName(Bind("filePath")) %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Target="_blank" runat="server" Text='<%# Path.GetFileName(Bind("filePath")) %>'
NavigateUrl='<%# Eval("filePath") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
In Gridview RowDataBound , evaluate filename from filepath.
System.IO.Path.GetFileName(filePath).
Not sure but you can try something like this:-
Text='<%# Eval("filePath").ToString().Split(Eval("filePath").ToString().LastIndexOf("/"))[1] %>'
May be you have stored it this way ~/Data/TestCopy.pdf in the database. You can use split function to split the last '/'
I have a gridview which pulls data from a database:
I wan't to make the content within task a linkbutton that can be clicked to show a popup with additional informatiom.
When I make the column linkbuttons it is also making Total: and Subtotal: a link button:
<asp:TemplateField HeaderText="Task" ItemStyle-Width="20%">
<ItemTemplate>
<asp:LinkButton ID="taskLinkButton" runat="server"
Text='<%# Eval("Task")%>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
How do I prevent these specific rows from being link buttons?
A bit dirty but this should do the trick:
So i coulnt get to call Databinder.Eval inside <% %>, I'm not sure if it's actually possible, so I went with a different solution. The following worked for me (and its even shorter than last version):
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton Text='<%# Eval("task") %>' Visible='<%# Eval("incidentN") != null %>' runat="server" />
<asp:Literal Text='<%# Eval("task") %>' Visible='<%# Eval("incidentN") == null %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
You can use a PlaceHolder with conditional visibility
<asp:PlaceHolder ID="Ok" runat="server" Visible='<%# (Eval("LoadStatus").ToString()=="false"?true:false) %>'><%----%>
<asp:Label ID="Label1" Text='<%# Eval("Task")%>' runat="server" />
</asp:PlaceHolder>
<asp:PlaceHolder ID="Ko" runat="server" Visible='<%# (Eval("LoadStatus").ToString()=="false"?false:true) %>'><%----%>
<asp:LinkButton ID="taskLinkButton" runat="server"
Text='<%# Eval("Task")%>'>
</asp:LinkButton>
</asp:PlaceHolder>
I have this aspx code:
<asp:TemplateField HeaderText="Name" SortExpression="Firmierung">
<ItemTemplate>
<asp:HyperLink ID="HyperLink" runat="server" NavigateUrl='<%#Eval("Id", "DetailInfo.aspx?Id={0}") %>' Text='<%#Bind("Name") %>' />
</ItemTemplate>
</asp:TemplateField>
I want to add an if condition so that I can use operand + with Text, something like this:
<asp:TemplateField HeaderText="Name" SortExpression="Firmierung">
<ItemTemplate>
<% if(Condition is true) { %>
<asp:HyperLink ID="HyperLink" runat="server" NavigateUrl='<%#Eval("Id", "DetailInfo.aspx?Id={0}") %>' Text='<%#Bind("Name") + ("Active") %>' />
<% } else { %>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%#Eval("Id", "DetailInfo.aspx?Id={0}") %>' Text='<%#Bind("Name") %>' />
<% } %>
</ItemTemplate>
</asp:TemplateField>
I don't know how to use operand + in this case. Any help appreciated. Thanks!
Try this one
Text='<%# String.Format({0}{1},Eval("Name"),Eval("Active")) %>'
OR
Text='<%# String.Format({0}{1},Bind("Name"),Bind("Active")) %>'
For more help visit the link:
HyperLink with NavigateUrl with Eval(). Where is the mistake?
You can't do it with Bind. Although with Eval you can add some C# code with it, with Bind it is not possible. Eval is really a method call but Bind is just a declaration that turned by the framework to some binding code, and its format has to be Bind("FieldName") (You can add formatting though).
The Hyperlink Text property is not editable by the client so Eval should be enough and you can write it in one row.
<asp:HyperLink ID="HyperLink" runat="server"
NavigateUrl='<%#Eval("Id", "DetailInfo.aspx?Id={0}") %>'
Text='<%# Eval("Name") + (Condition ? + Eval("Active") : "") %>' />