Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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="/KB/answers/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.

XML
<asp:GridView ID="Manage_Classieds" runat="server" AutoGenerateColumns="False" BackColor="LightGoldenrodYellow"
               BorderColor="Tan" BorderWidth="1px" CellPadding="2" AllowPaging="True" PageSize="3" OnPageIndexChanging="GridView1_PageIndexChanging1"

               Font-Bold="False" Font-Names="Arial" Font-Size="9pt" ForeColor="Black" GridLines="None" ShowHeader="False">
               <FooterStyle BackColor="Tan" />
               <PagerStyle ForeColor="Black"
              BackColor="#C6C3C6"></PagerStyle>
                <Columns>
                   <asp:TemplateField>
                       <ItemTemplate>

                        <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>&nbsp;<%#Eval("Description")%></br><b>Price:</b>&nbsp;<%#Eval("Price")%></b> <br/><b> DateTime Uploaded:</b>&nbsp;<%#Eval("DateTime")%></b></td></tr><tr><td  align="right"colspan='2' ><a  href='DetailDescription.aspx? '>View Agent Details</a> </td>  </tr></table><br/>

                       </ItemTemplate>
                   </asp:TemplateField>
               </Columns>
               <AlternatingRowStyle BackColor="PaleGoldenrod" />
               <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
               <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
               <HeaderStyle BackColor="Tan" Font-Bold="True" />
               </asp:GridView>
Posted
Updated 9-Apr-11 2:53am
v2
Comments
Dalek Dave 9-Apr-11 8:53am    
Edited for Grammar and Readability.

Override the data bound event and set the hyperlink appropriately from there
 
Share this answer
 
Comments
Dalek Dave 9-Apr-11 8:54am    
Good Call.
hinzhonee 9-Apr-11 17:11pm    
but i want to use grid view..can u give me the code how to do it in grid view...
Its Better for you To use case in your dataBase Query

SQL
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)



It will give you result as Required and then
and then in aspx Page You simply have to write

XML
<asp:HyperLink ID="hyp_Isfresher" NavigateUrl='<%#"~/Admin/CandidateExperienceDetails.aspx?Id="+Eval("CandidateID") %>'
                                               Text='<%#Eval("IsFresher")%>' runat="server"></asp:HyperLink>
 
Share this answer
 
Comments
Dalek Dave 9-Apr-11 8:54am    
Good Answer, very comprehensive.
hinzhonee 9-Apr-11 16:55pm    
thanks alot...i hope it i will work..can u tell me what is isFresher..is it a variable or what?
hinzhonee 9-Apr-11 17:57pm    
Thanks alot..it really worked
i achieved the solution using this code...

ALTER PROCEDURE dbo.AdminManageClassifieds

AS


SELECT Classified_ID,Description,Duration,[DateTime],AgentID,AdminID,Title,Price ,Visibility=
CASE Visibility
WHEN 'true' THEN 'Delete'
WHEN 'false' THEN 'Verify'

END
from Classifieds

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900