[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 450
  • Last Modified:

Formatting one column of gridview based on value of another column

Hi,

I am programming a web application in VB.NET.

I have a Gridview that I would like to display that lists document names, and their links. When the user clicks on the link - they will have access to the document.

The list of documents is in a database table called 'msgdocs'. The column with the document link is called 'linkURL' and the column with the type of link is called 'linktype'.

The problem is, I have 4 different types of documents (linktypes):

1. PDF documents - when the user clicks on this document, I would like it to open in a window... something like onclick="window.open('linkURL',null, 'width=700,height=500'); return false"

2. Other local documents - just have the browser download the document (ex: like a powerpoint file)

3. External documents - have the browser open a new tab (ie: code would be <a href='linkURL' Target = '_blank')

4. Another page on the portal - have the browser refresh the current page (ex: using a querystring variable, code would be 'mypage.aspx?pagnum=4')

So what I am trying so understand is how it could be possible to "wrap" the 'linkURL' in code to provide the above 4 behaviours, based on the value of the 'linktype' column.

Perhaps using onrowdatabound ?

Help !

Thanks, Pete
0
pbissegger
Asked:
pbissegger
  • 3
  • 2
1 Solution
 
CodeCruiserCommented:
You can use the RowDataBound event to add logic around this

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
0
 
pbisseggerAuthor Commented:
OK,

I have rowdatabound that creates #2 and #3 above. But I am having problems with the PDf window.open functionality.

Here's a subset of my code:

    If e.Row.RowType = DataControlRowType.DataRow Then
  
        link1 = e.Row.Cells(5).Text

        Select Case e.Row.Cells(0).Text
            Case "0" ' There is no link, just display "-"
                e.Row.Cells(5).Text = "-"
            Case "1" ' External link, open in new tab
                e.Row.Cells(5).Text = "<a href='" & link1 & "' target='_blank'>" & right(link1,3) & "</a>" 
            Case "2" ' Internal document, just download
                e.Row.Cells(5).Text = "<a href='docs/" & e.Row.Cells(5).Text & "'>" & right(link1,3) & "</a>"
            Case "3" ' PDF document, open popup window
                e.Row.Cells(5).Text = "<a href='javascript:void(0)' onclick='window.open('docs/" & link1 & "','')'>" & right(link1,3) & "</a>"
            Case "4" ' Internal document, just refresh page with new querystring
                ' Call LoadDocument routine with an ID 
        End Select

    End If

  End Sub

Open in new window


but the PDF functionality isn't working. When I copy the link it just shows the "link" as void(0) ... I don't know what is happening to the rest of it.

I have also tried:

e.Row.Cells(5).Text = "<a href='javascript:window.open('docs/" & link1 & "')'>" & right(link1,3) & "</a>"

but that doesn't work either.

I need help with the syntax to get it right.

Thanks, Peter
0
 
CodeCruiserCommented:
>e.Row.Cells(5).Text = "<a href='javascript:void(0)' onclick='window.open('docs/" & link1 & "','')'>" & right(link1,3) & "</a>"

>When I copy the link it just shows the "link" as void(0)

That's because you set it to void(0). Does clicking it work? Why don't you just add a plain link?
0
 
pbisseggerAuthor Commented:
Codecruiser,

I was looking for a solution to open up a browser in a popup. The only way I know how to do this is on window.open.

Is there another way to do this  using a hyperlink ?

Thanks, peter
0
 
CodeCruiserCommented:
You already have

Case "1" ' External link, open in new tab
                e.Row.Cells(5).Text = "<a href='" & link1 & "' target='_blank'>" & right(link1,3) & "</a>"

Using target="_blank" opens in new window/tab.

You did not say what happens when you click your current link.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now