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

Details Grid - Hyperlink Value

2 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Samantha
Top achievements
Rank 1
Samantha asked on 07 Jan 2011, 06:06 PM
I am new to Telerik - and fairly new to ASP.NET - so please bare with me...

I have one master grid - and one detail grid.  In the detail grid I have a hyperlink (Link Button).

This hyperlink is meant to open an Image (PDF) in my SQL database.  

I figured I would do this by sending the value of the clicked item (a GUID) to the code behind - so I can then search for the image and open it up. Whatever I do, I can't figure out how to pass the GUID that was selected to the code behind.

I was able to get the value of every GUID in the column - but not the one I selected.  Could anyone steer me on the right path?  I have spent days trying to do this - I would think that this should be fairly easy...

HTML
<asp:LinkButton runat="server" CausesValidation="false" CommandName="Select"
    Text="View"></asp:LinkButton>

VB.NET
Protected Sub RadGrid2_SelectedIndexChanged(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid2.SelectedIndexChanged
 
    Dim gridDataItem As GridDataItem = TryCast(e.Item, GridDataItem)
    If e.Item.OwnerTableView.GetColumnSafe("GUID") IsNot Nothing Then
 
        Dim cell As TableCell = TryCast(gridDataItem("GUID"), TableCell)
    End If
End Sub

2 Answers, 1 is accepted

Sort by
0
Mike Nogen
Top achievements
Rank 1
answered on 07 Jan 2011, 08:32 PM
Hello!

I´m not sure how you have stored the information of your PDF files in database. Is it in binary format or is it just a link/url to your file? I suggest that you make a special .ASPX page or a "popup" page that you redirekt to wich take the database ID for the selected PDF file as QueryString parameter and just Response out the content from that page. If you could ge me more information I could get you a better answer, I think.

This example just answer
" I can't figure out how to pass the GUID that was selected to the code behind."

But I think that the easiest way is to use a GridButtonColumn
<telerik:GridButtonColumn ButtonType="PushButton" Text="ShowPDFFileViaLink" CommandName="ShowPDFFileViaLink"></telerik:GridButtonColumn>
                <telerik:GridButtonColumn ButtonType="PushButton" Text="ShowPDFFileViaBlob" CommandName="ShowPDFFileViaBlob"></telerik:GridButtonColumn>

And do what you want on those events.
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridDataItem selectedItem = RadGrid1.Items[e.Item.ItemIndex];
            int databaseID = int.Parse(selectedItem["ID"].Text);
  
            switch (e.CommandName)
            {
                case "ShowPDFFileViaLink":
                    RedirectToPDFLink(databaseID);
                    break;
                case "ShowPDFFileViaBlob":
                    SendBinaryToClient(databaseID);
                    break;
            }
  
        }

private void RedirectToPDFLink(int databaseID)
        {
            Response.ContentType = "application/pdf";
            byte[] binaryPDF = GetPDFLinkFromDatabase(databaseID);
            Response.BinaryWrite(binaryPDF);
        }
private byte[] GetPDFLinkFromDatabase(int databaseID)
       {
           string linkToPDF = string.Empty;
           byte[] binaryPDF = null;
           using (Model.PDFDataContext db = new PDFGrid.Model.PDFDataContext())
           {
               var dbPDF = (from pdf in db.PDFInformations
                            where pdf.ID.Equals(databaseID)
                            select pdf).FirstOrDefault();
               if (dbPDF != null)
               {
                   //Either use the link to the PDF to do something with that
                   linkToPDF = dbPDF.PDFLink;
                   //Or read out the PDF file from file system and send as Binary to the client
                   binaryPDF = System.IO.File.ReadAllBytes(dbPDF.PDFLink);
               }
                 
           }
           return binaryPDF;
       }

0
Samantha
Top achievements
Rank 1
answered on 10 Jan 2011, 03:58 AM

Tags
Grid
Asked by
Samantha
Top achievements
Rank 1
Answers by
Mike Nogen
Top achievements
Rank 1
Samantha
Top achievements
Rank 1
Share this question
or