Link Button question

D

Darren Clark

I have a link button that i would like to be used if the value of the text is NOT 0...

So the code below will always make a linkbutton....

However if the value of "DataBinder.Eval(Container,"DataItem."+ JR.Core.Data.JobseekerData.FLD_SEARCH_MATCHES) " is 0 i do not want the the 0 to become a link.... I simply want to display it as text.

How can i do this?

<asp:LinkButton
CommandArgument='<%# DataBinder.Eval(Container,"DataItem."+ JR.Core.Data.JobseekerData.FLD_SEARCH_ID) +","+ DataBinder.Eval(Container,"DataItem."+ JR.Core.Data.JobseekerData.FLD_SEARCH_PROFILE_ID)%>'
CommandName='ProfileMatch'
id="ProfileMatch_Text" OnCommand="TextLinkClick" Runat=server CssClass="body_text">
<%# DataBinder.Eval(Container,"DataItem."+ JR.Core.Data.JobseekerData.FLD_SEARCH_MATCHES) %>
</asp:LinkButton>
 
A

Andrew

Darren,

Using the LinkButton, from my understanding will always give you a link regardless of what you give it. I had a DataGrid where I wanted somthing similar in a column, so I used a Label control in a templated column, and then created a function on the Code-Behind page that would receive the "DataBinder.Eval()" statement and return the full <A HREF> tag or a simple string depending on the data. But that sent the user off to another page, and if that is what you want, give it a try.

(I do VB.net)
Down and dirty example of what I did in the DataGrid:

Html side
<TemplateColumn>
blah blah blah
....
<asp:Label id="MyLabel" runat="server" Text='<%# ToLinkOrNot(DataBinder.Eval([data-item]) %>' />
</TemplateColumn>

Code-Behind
Private Function ToLinkOrNot(ByVal MyData As Object) As String
If CType(MyData, Double) = 0 Then
Return "Hello World!"
Else
Return "<A HREF=""mypage.aspx"">Hello World!</A>"
End If
End Function

But if you need the Link Button because you want to do a postback when a link is neeed, then you might try using both a regular Label Control and a Link Button side by side, and use a function on the code-behind page that would, based on the data you send it, populate and set Visible=True for the one you need.

Just a thought, hope it is in some way useful/helpful. :)

-- Andrew


I have a link button that i would like to be used if the value of the text is NOT 0...

So the code below will always make a linkbutton....

However if the value of "DataBinder.Eval(Container,"DataItem."+ JR.Core.Data.JobseekerData.FLD_SEARCH_MATCHES) " is 0 i do not want the the 0 to become a link.... I simply want to display it as text.

How can i do this?

<asp:LinkButton
CommandArgument='<%# DataBinder.Eval(Container,"DataItem."+ JR.Core.Data.JobseekerData.FLD_SEARCH_ID) +","+ DataBinder.Eval(Container,"DataItem."+ JR.Core.Data.JobseekerData.FLD_SEARCH_PROFILE_ID)%>'
CommandName='ProfileMatch'
id="ProfileMatch_Text" OnCommand="TextLinkClick" Runat=server CssClass="body_text">
<%# DataBinder.Eval(Container,"DataItem."+ JR.Core.Data.JobseekerData.FLD_SEARCH_MATCHES) %>
</asp:LinkButton>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top