[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

disable link in gridview

Posted on 2008-02-03
5
Medium Priority
?
842 Views
Last Modified: 2008-02-07
I have a link in a gridview that when clicked brings up another page with detailed information about the record.  However, there are certain records in the gridview that do not have detailed information, this is when I'd like to disable the 'View Details' hyperlink.  How can this be accomplished?  Here is my attempt, but of course is not working:

If GridView1.Rows.Item(4).ToString = "A" Then

            GridView1.Columns.Item(0).Visible = False
            GridView1.Columns.Item(1).Visible = False
0
Comment
Question by:newbieal
  • 2
  • 2
5 Comments
 
LVL 4

Author Comment

by:newbieal
ID: 20811067
This is not working for me.  I tried the VB example.

I get this error:

A is neither a DataColumn nor a DataRelation for table DefaultView.

When implementing this code:


 <asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("A_ID", "test3.aspx?A_ID={0}") %>'
                            Text="View A"></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>


 Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim drv As System.Data.DataRowView = DirectCast(e.Row.DataItem, Data.DataRowView)
            Dim a As HyperLink = DirectCast(e.Row.FindControl("View A"), HyperLink)
            If drv("A") Then
                a.Visible = False
            Else
               a.Visible = True
            End If
        End If

    End Sub
0
 
LVL 1

Accepted Solution

by:
safitech earned 1500 total points
ID: 20811979
Are you trying to read a value from a control in the GridView or from the underlying data source?

If you're reading a control value, say a label, you could use more or less the same code you already have (sub in your control name):

         If e.Row.RowType = DataControlRowType.DataRow Then
            Dim drv As System.Data.DataRowView = DirectCast(e.Row.DataItem, Data.DataRowView)
            Dim a As HyperLink = DirectCast(e.Row.FindControl("View A"), HyperLink)
            Dim testControl As Label = DirectCast(e.Row.FindControl("LabelName"), Label)
            If testControl.Text = "A" Then
                a.Visible = False
            Else
               a.Visible = True
            End If
        End If
0
 
LVL 4

Author Comment

by:newbieal
ID: 20813901
Once of the columns is named colum A and the data displayed in it could be, A, B, or C.  I want to test for one of these values.  If A, then disable hyperlink.  I believe the example you gave won't work with this?
0
 
LVL 1

Expert Comment

by:safitech
ID: 20838050
Like I say, that should work if you're displaying the value of that column in a Label, but maybe that's not what you're doing.  

Perhaps you could clarify the question by showing the GridView and DataSource declarations.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses

607 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