Solved

Hiding Content within a Gridview's Itemtemplate field

Posted on 2006-10-20
7
476 Views
Last Modified: 2008-03-06
Hi All

I have a Gridview which is databound to a SQL DB table. One of the columns within my SQL table is called LINK and it contains an ID for each record. What I want to do within a Gridview column is be able to provide an ASp:Hyperlink with the ID appended as a query string which I can do no problem.

BUT!... How could I hide the ASP:Hyperlink if an ID isn't supplied?

Many thanks

Rit
0
Comment
Question by:rito1
  • 4
  • 2
7 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 17775196
If you have an ID that you are using from the DB it should be set as the primary key of the table and set to be an int value with Identity set to true. This will ensure all records have an ID and you won't have to worry about it. Is there some reason you cannot do this?
0
 
LVL 1

Expert Comment

by:stto3703
ID: 17775236
Bind the hyperlink's "Visible" field to the id.
0
 
LVL 1

Author Comment

by:rito1
ID: 17775321
Hi stto3703

Sorry to ask but how do you bind the hyperlink's visible property to the ID?

strickdd, its not a primary key... the ID is optional in this scenario.

Rit
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Expert Comment

by:stto3703
ID: 17776366
So "link" is a Column of your table with some fields being NULL, correct?

This would be the easiest way if you use VS2005 or VWD:
Edit your grid's columns. Convert LINK to a "Template Field"

Then go to edit Templates by clicking the small triangle on the top-right corner of your grid.

Select the Link item field, remove whatever Control is currently there, drag a Hyperlink and click on the Hyperlink's small triangle and select "Edit Databindings". If "Visible" is not part of the list select Show all Properties (not sure if this is the correct wording).

Now just select your DB field as "LINK". To format the Hyperlink change the Text binding and the URL. The url would be something like "mypage.aspx?value={0}" and {0} is whatever your link value is.
0
 
LVL 1

Accepted Solution

by:
stto3703 earned 500 total points
ID: 17776545
Here's how your TemplateField tag should look like after your done with the above: (of course my field names are different)
The item in bold is important

<asp:TemplateField HeaderText="links" SortExpression="links">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("links") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("qid", "test.apsx?{0}") %>'
                        Text='<%# Eval("qtitle") %>' <b>Visible='<%# DataBinder.Eval(Container.DataItem, "links").ToString()!="" %>' </b>></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
0
 
LVL 1

Expert Comment

by:stto3703
ID: 17776577
FYI: Bold is <b> .... </b>
0
 
LVL 1

Author Comment

by:rito1
ID: 17777177
Hi stto3703

Thank you for you guidance. Taking you code as is I found that it was hiding the LINK field data rather than showing it. I also couldn't get the hyperlink to work either only show the text. But with your guidance on syntax etc.. I managed to get it towork with the following:

<asp:TemplateField>
                <ItemTemplate>
      <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "news.aspx?newsid=" & Eval("LINK") %>'
      Visible='<%# IsDBNull(Eval("LINK")).ToString = "False" %>' Text="Further Info..."></asp:HyperLink><br />
                </ItemTemplate>
            </asp:TemplateField>

Any guidance on making my code above better is always open.

Again, many thanks

Rit
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now