This is a migrated thread and some comments may be shown as answers.

Cannot open a PDF file from Hyperlinkcolumn Radgrid

13 Answers 240 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sudhakar
Top achievements
Rank 1
sudhakar asked on 25 Feb 2011, 04:42 AM
Hello Telerik Team,

Need urgent help from you guys.

1) i am displaying all PDF files stored on Directory from specific path inside the radgrid using "GridHyperLinkColumn".

2) the display is perfect but when clicked on the link the path taken is not fully correct and Hence cannot open the Files.

Actual Path ="../help/PDFfiles/*.pdf"
Path Taken = "../help/*.pdf"
It cannot take PDFFiles folder and hence fiel cannot be display
Please help for the same. Below is the code as shown.

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <telerik:RadGrid ID="gridFilesDisplay" runat="server" >
                       <MasterTableView EditMode="InPlace" ShowHeadersWhenNoRecords="true" AllowFilteringByColumn="false">
                <Columns>
   <telerik:GridHyperLinkColumn DataNavigateUrlFields="Name" DataTextField="Name" HeaderText="Document Name">    ></telerik:GridHyperLinkColumn>            
                 </Columns>
                    <PagerStyle Mode="NextPrevNumericAndAdvanced" />
              </MasterTableView>
        </telerik:RadGrid>
    </form>
  
************************** CODEBEHIND******************************
  
protected void Page_Load(object sender, EventArgs e)
        {
  
            if (!IsPostBack)
            {
                      sPath = "..//help/PDFFILES//"    //(This value taken from webconfig)
                DirectoryInfo objDirectory = new DirectoryInfo(Server.MapPath(sPath));
                   
                 gridFilesDisplay.DataSource = objDirectory.GetFiles("*.pdf");
                gridFilesDisplay.DataBind();
            }
  
}

 

13 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 03 Mar 2011, 08:33 AM
Hello,

RadGrid displays what it is bound to, so have you tried debugging the data-binding to confirm that the values passed to the grid control are what you expect it to display?

Additionally, if you are going to enable editing for the grid, I would advise you to use advanced data-binding, instead of simple.


Regards,
Tsvetina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
sudhakar
Top achievements
Rank 1
answered on 04 Mar 2011, 10:15 AM
Hi Tsvetina ,

Thankyou for your reply.

I solved myself by using additional objects in itemdatabound of the grid.
Thanks..!!

Regards
Sudhakar
0
Rick
Top achievements
Rank 1
answered on 04 Apr 2014, 01:08 PM
Sudhakar,

I am trying to do something similar... I think.  I want to have a hyperlink in the grid that will do either of the following:

1 - Open the folder specified in the link

 OR

2 - Open all the PDF files located in the folder specified in the link.

If you (or anyone else) is able to help with this, it would be much appreciated.
0
Kostadin
Telerik team
answered on 09 Apr 2014, 07:55 AM
Hi Rick,

I assume you are trying to display all files in chosen directory at your server. Since this is not possible by using a RadGrid I would recommend you to add RadFileExporer control in your project. Please check out the following live example and our documentation for additional information.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jeffrey
Top achievements
Rank 1
answered on 09 May 2014, 03:21 PM
Thank you.  It looks like I need to use command buttons to select rows.  I was allowing the user to drag the mouse to select rows.  

Is there a way to allow the user to drag to select rows?  This is much easier, faster, and efficient for the end user.
0
Rick
Top achievements
Rank 1
answered on 09 May 2014, 04:01 PM
(Ignore Jeffrey-- I was logged onto a co-workers account)

Thank you.  It looks like I need to use command buttons to select rows.  I was allowing the user to drag the mouse to select rows.  

Is there a way to allow the user to drag to select rows?  This is much easier, faster, and efficient for the end user.
0
Kostadin
Telerik team
answered on 14 May 2014, 08:13 AM
Hello Rick,

I am afraid I am not completely understand your requirement. Could you please elaborate a little bit more on your scenario?

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rick
Top achievements
Rank 1
answered on 14 May 2014, 04:35 PM
I have a grid with 16 displayed columns and 10 more which are not displayed.  I want the user to be able to drag the mouse to select rows rather than to press a "Select" button in the grid.  Once the user selects the rows, they would press a button on the page which exports all of those rows to Excel.

This much I have working, HOWEVER, I am using Column Groups and in order for those to be displayed properly, I have to issue a rebind.  The rebind makes the Column groups appear properly, but all of the rows on the page are exported rather than the selected rows.

I believe that the solution you linked requires that the Select command is pressed for each row.  Is there a way around that so they could drag to select?  Or perhaps, when the user drags, it recreates the manual clicking of the select button for each row selected?

0
Kostadin
Telerik team
answered on 19 May 2014, 11:22 AM
Hi Rick,

A possible solution is to hook OnItemDataBound event handler and set Visible to false to all items which are not selected. Please check out the following code snippet.
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem && isExport)
    {
        GridDataItem item = e.Item as GridDataItem;
        if (!item.Selected)
        {
            item.Visible = false;
        }
    }
}
 
bool isExport = false;
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToExcelCommandName)
    {
        isExport = true;
    }
}

Please let me know if that approach serves your needs.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rick
Top achievements
Rank 1
answered on 19 May 2014, 01:17 PM
This does not work either.  While the code runs to set the item visible, all items are still visible when exported.  One difference is that I have a button on the form that calls the export, it is not in the grid.  Here is my code.

Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As EventArgs)
 
 
        isExport = True
 
        Me.RadGrid1.MasterTableView.GetColumn("Location").Display = True
        Me.RadGrid1.MasterTableView.GetColumn("Proposal_NotIssued").Display = True
        Me.RadGrid1.MasterTableView.GetColumn("Proposal_NotIssuedReason").Display = True
        Me.RadGrid1.MasterTableView.GetColumn("Proposal_Qualification").Display = True
        Me.RadGrid1.MasterTableView.GetColumn("Proposal_EstimatedProjectArea").Display = True
        Me.RadGrid1.MasterTableView.GetColumn("Proposal_EstimatedConstructionCost").Display = True
        Me.RadGrid1.MasterTableView.GetColumn("Proposal_WinningProbabilityPct").Display = True
        Me.RadGrid1.MasterTableView.GetColumn("Proposal_DateGranted").Display = True
        Me.RadGrid1.MasterTableView.GetColumn("Proposal_ProjectID").Display = True
        Me.RadGrid1.MasterTableView.GetColumn("Proposal_Comments").Display = True
 
        For Each item As GridDataItem In Me.RadGrid1.Items
            If item.Selected = False Then
                item.Visible = False
            End If
        Next
 
        Me.RadGrid1.Rebind()
 
        Me.RadGrid1.ExportSettings.ExportOnlyData = True
        Me.RadGrid1.ExportSettings.OpenInNewWindow = True
        Me.RadGrid1.ExportSettings.FileName = "Selected Proposals " & Format(Now, "yyyy-MM-dd-h-mm-ss")
        'Me.RadGrid1.ExportSettings.IgnorePaging = True
        Me.RadGrid1.ExportSettings.UseItemStyles = True
        Me.RadGrid1.MasterTableView.ExportToExcel()
 
    End Sub
Private Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
 
    If TypeOf e.Item Is GridDataItem AndAlso isExport Then
        Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
        If Not item.Selected Then
            item.Visible = False
        End If
    End If
 
End Sub
 
Private isExport As Boolean = False
0
Rick
Top achievements
Rank 1
answered on 19 May 2014, 01:42 PM
I looked at what is happening as it runs.  

The rebind in the btnExport_Click triggers the RadGrid1_ItemDataBound.  There grid page contains 20 items.  The first six times the ItemDataBound is run, the criteria is not met.  The next 20 times, it is met and item.visible is set to false.  This is the case regardless of how many items are actually selected.

So it would seem like the code is reading that nothing is selected, yet it's exporting everything.

Also, I ran this with and without the following code in the command button and it's the same.

For Each item As GridDataItem In Me.RadGrid1.Items
    If item.Selected = False Then
        item.Visible = False
    End If
Next

0
Rick
Top achievements
Rank 1
answered on 19 May 2014, 02:01 PM
I don't know how to do this, BUT what if prior to the REBIND, I save the selected items to an array and after the rebind I select the items based on what is in the array...
0
Kostadin
Telerik team
answered on 22 May 2014, 08:22 AM
Hi Rick,

You have to either call Rebind() or enable the IgnorePaging property in order to fire the ItemDataBound event handler and disable the items which are not selected.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
sudhakar
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
sudhakar
Top achievements
Rank 1
Rick
Top achievements
Rank 1
Kostadin
Telerik team
Jeffrey
Top achievements
Rank 1
Share this question
or