?
Solved

Should be very simple show/hide gridview element

Posted on 2007-11-15
5
Medium Priority
?
569 Views
Last Modified: 2010-04-21
I'm bashing my head using VB ASP.Net. This stuff is simple in ColdFusioon but I can't find the way to do this anywhere.

I have a gridview called GridView1. In this grid I have a TemplateField:
<asp:TemplateField>
                                        <ItemTemplate>
                                              <asp:LinkButton ID="LinkButton1" Visible="False" CommandArgument='<%# Eval("eadocsID") %>'
                                              CommandName="DeleteRow" runat="server"
                                              OnClientClick='return confirm("Are you sure want to delete this record?")'
                                              Font-Strikeout="False" Font-Bold="True" ForeColor="Green">Delete</asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>

I have set visible to false. On the code behind, I'm trying to say if your cookie contains one of these values, set the Visible property to true:

If Request.Cookies("employee")("employeeid") = "241" Or "146" Or "8" Or "172" Then
            GridView1.Visible = True
        End If

Obviously, Gridview1.Visible isn't going to work, but I don't know how to reference LinkButton1 as it says it's not defined.

Please help!!!
0
Comment
Question by:radleydp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 20293143
you have to use the gridview's rowdatabound event, find the linkbutton using "findcontrol", then set it:

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim lb As LinkButton
            lb = e.Row.FindControl("LinkButton1")
            If Request.Cookies("employee")("employeeid") = "241" Or "146" Or "8" Or "172" Then
                lb.Visible = False
            End If
        End If
    End Sub

Open in new window

0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 400 total points
ID: 20293159
actually, just realized that you can't use "Or" like that, so try:
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim lb As LinkButton
            lb = e.Row.FindControl("LinkButton1")
            If Request.Cookies("employee")("employeeid") = "241" Or Request.Cookies("employee")("employeeid") = "146" Or Request.Cookies("employee")("employeeid") = "8" Or Request.Cookies("employee")("employeeid") = "172" Then
                lb.Visible = False
            End If
        End If
    End Sub

Open in new window

0
 
LVL 16

Assisted Solution

by:GreymanMSC
GreymanMSC earned 400 total points
ID: 20294735
Just a slight tweak to the above solution.  It's far more elegant coding to use the Select condition to compare one item to a list of values.  It is much neater.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim lb As LinkButton = CType(e.Row.FindControl("LinkButton1"), LinkButton)
        If Not lb Is Nothing Then
            Select Case Request.Cookies("employee")("employeeid") 
            Case "241", "146", "8", "172" 
                lb.Visible = False
            Case Else
                lb.Visible = True 'just in case
            End Select
        End If
    End If
End Sub

Open in new window

0
 

Author Comment

by:radleydp
ID: 20298076
Thanks guys, I had to make a slight tweak adding Handles GridView1.RowDataBound to the first line, but otherwise both solutions work great!
0
 

Author Closing Comment

by:radleydp
ID: 31409457
Perfect!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 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