By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

Link Button question

P: n/a
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>

Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
"Darren Clark" <dc******@hotmail.com> wrote in message news:wt****************@news-server.bigpond.net.au...
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>

Nov 18 '05 #2

P: n/a
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
"Darren Clark" <dc******@hotmail.com> wrote in message news:wt****************@news-server.bigpond.net.au...
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>

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.