根据数据库字段值动态更改超链接文本 [英] change hyperlink text dynamically based on database field value
问题描述
嗨!
我想动态显示超链接.
例如在模板字段列中,我想基于数据绑定值显示超链接.
如果数据库列标题的值为"true",我想显示带有文本"delete"的超链接,如果值是"false",我想显示带有文本"verify"的超链接.
我不知道如何在此网格视图中使用if else语句.
<a href=''Admin.aspx?C_id=<%#Eval("Classified_ID")%> ''> <%# Eval("Title") %>Verify</a>
这是代码.
我想根据标题"值更改此超链接的文本,请让我知道如何实现.
Hi!
I want to display a hyperlink dynamically.
e.g In template field column I want to display a hyperlink based on the data bound value.
If the value of database column title is "true" I want to display hyperlink with the text "delete" and if the value is "false " I want to display the hyperlink with the text "verify".
I dont know how to use the if else statements in this grid view.
<a href=''Admin.aspx?C_id=<%#Eval("Classified_ID")%> ''> <%# Eval("Title") %>Verify</a>
Here is the code.
I want to change the text of this hyperlink based on "title " value, please let me know how I can achieve this.
<pre lang="xml"><asp:GridView ID="Manage_Classieds" runat="server" AutoGenerateColumns="False" BackColor="LightGoldenrodYellow"<br />
BorderColor="Tan" BorderWidth="1px" CellPadding="2" AllowPaging="True" PageSize="3" OnPageIndexChanging="GridView1_PageIndexChanging1"<br />
<br />
Font-Bold="False" Font-Names="Arial" Font-Size="9pt" ForeColor="Black" GridLines="None" ShowHeader="False"><br />
<FooterStyle BackColor="Tan" /><br />
<PagerStyle ForeColor="Black"<br />
BackColor="#C6C3C6"></PagerStyle><br />
<Columns><br />
<asp:TemplateField><br />
<ItemTemplate><br />
<br />
<table width=''600px'' border=''1''> <tr ><td ><b><%# Eval("Title")%></b></td><td ><a href=''Admin.aspx?C_id=<%#Eval("Classified_ID")%> ''> <%# Eval("Title") %>Verify</a> </td></tr><tr ><td colspan="2" ><b>Description:</b> <%#Eval("Description")%></br><b>Price:</b> <%#Eval("Price")%></b> <br/><b> DateTime Uploaded:</b> <%#Eval("DateTime")%></b></td></tr><tr><td align="right"colspan=''2'' ><a href=''DetailDescription.aspx? ''>View Agent Details</a> </td> </tr></table><br/><br />
<br />
</ItemTemplate><br />
</asp:TemplateField><br />
</Columns><br />
<AlternatingRowStyle BackColor="PaleGoldenrod" /><br />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" /><br />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" /><br />
<HeaderStyle BackColor="Tan" Font-Bold="True" /><br />
</asp:GridView></pre><br />
推荐答案
覆盖数据绑定事件并从那里适当设置超链接
Override the data bound event and set the hyperlink appropriately from there
使用案例更好在您的数据库查询中
Its Better for you To use case in your dataBase Query
CREATE procedure Procedurename
(
@Query varchar(500)
)
as
declare @CaseSyntax varchar(500)
set @CaseSyntax='case CandidateDetails.IsFresher
when 0 then ''Fresher''
when 1 then ''Experience''
end as Isfresher '
exec ('select InterviewCategories.Category,CandidateDetails.CandidateID,CandidateDetails.FirstName+CandidateDetails.LastName as Name,
CandidateDetails.ContactNo,CandidateDetails.Email,'+ @CaseSyntax +'
,
Qualification.QualificationName,CONVERT(CHAR(10),CandidateDetails.CreatedOn, 105) as Date from CandidateDetails
inner join InterviewCategories on CandidateDetails.InterviewCategoryId = InterviewCategories.InterviewCategoryID
inner join Qualification on CandidateDetails.QualificationID = Qualification.QualificationId '+@Query)
上的内部联接Qualification
它将为您提供要求的结果,然后
然后在aspx页面中,您只需编写
It will give you result as Required and then
and then in aspx Page You simply have to write
<asp:HyperLink ID="hyp_Isfresher" NavigateUrl='<%#"~/Admin/CandidateExperienceDetails.aspx?Id="+Eval("CandidateID") %>'
Text='<%#Eval("IsFresher")%>' runat="server"></asp:HyperLink>
这篇关于根据数据库字段值动态更改超链接文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!