radgrid hyperlink column

21 posts, 1 answers
  1. dwarak kanniah
    dwarak kanniah avatar
    14 posts
    Member since:
    Oct 2009

    Posted 23 Nov 2009 Link to this post

    Hi,

     I am creating the datasource from datatable and populating the radgrid. i want to make cells as hyperlink column and navigate to url based on the cell value in the code behind. could anyone help regarding this issue.

    thanks
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Nov 2009 Link to this post

    Hello Dwarak,

    You can make use of the GridHyperLinkColumn to achieve the required. You can set the DataNavigateUrlFields to the required datafieldin the database, inorder to specify the target of the hyperlink. Check out the following document various column types supported by RadGrid.
    Column types

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. dwarak kanniah
    dwarak kanniah avatar
    14 posts
    Member since:
    Oct 2009

    Posted 23 Nov 2009 Link to this post

    Hi Princy,
                
               Could you send the code snippet how to do it in the code behind.

    Thanks,
    Dwarak

     
  5. dwarak kanniah
    dwarak kanniah avatar
    14 posts
    Member since:
    Oct 2009

    Posted 23 Nov 2009 Link to this post

    Hi Princy,

                    Thanks for the post.

    Thanks
    Dwarak
  6. Mohammed
    Mohammed avatar
    9 posts
    Member since:
    Jun 2009

    Posted 05 Jun 2011 Link to this post

    Dear,

    I tried what you have mentioned, but it is not working, I have a data table field called "PDF" that contains a link(PATH) to a  PDF file, I want to add a hyperlink to the radgrid to let users to download pdf files. I have set the DataNavigateUrlFields="PDF" but it is not working:


     <telerik:GridHyperLinkColumn UniqueName="PDF" 
                FilterControlAltText="Filter column column" DataNavigateUrlFields="PDF" 
                Text="Download" >
                        </telerik:GridHyperLinkColumn>

    could you please help.
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Jun 2011 Link to this post

    Hello Mohammed,

    Try setting the DataNavigateUrlFormatString property for the HyperLinkColumn. Hope this helps you.

    aspx:
    <telerik:GridHyperLinkColumn  DataTextFormatString="Welcome to Google"
                            DataNavigateUrlFields="PDF" UniqueName="EmailId" DataNavigateUrlFormatString="PDF"
                           HeaderText="HyperLink<br/>Column" DataTextField="EmailId">
    </
    telerik:GridHyperLinkColumn>

    Thanks,
    Princy
  8. Mohammed
    Mohammed avatar
    9 posts
    Member since:
    Jun 2009

    Posted 06 Jun 2011 Link to this post


    Thank you so much Princy, it worded.


    Regards,
  9. Ram
    Ram avatar
    97 posts
    Member since:
    Jun 2011

    Posted 30 Jun 2011 Link to this post

    Hi
    I'm using RadGrid in my project.
    I'have gridhyperlinkcolumn in my grid and its working  well but
    I want to disable the underline for hyperlink.
    How can I achieve that please help me its mandatory and urgent
    Thanks.

  10. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Jun 2011 Link to this post

    Hello Ram,

    Try the following code snippet in ItemDataBound event to remove underline in HyperLinkColumn. Hope this helps.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = (GridDataItem)e.Item;
               HyperLink link = (HyperLink)item["HyperLinkColumn"].Controls[0];
               link.CssClass = "hidelink";
           }     
    }

    CSS:
    <style type="text/css">
            .hidelink
           {
               text-decoration:none;
           }
    </style>


    Thanks,
    Shinu.
  11. Ram
    Ram avatar
    97 posts
    Member since:
    Jun 2011

    Posted 30 Jun 2011 Link to this post

    Hi thanks for reply
    But I'm getting "Cannot find a cell bound to column name 'HyperLinkColumn'" error in databound event.
    can u pls verify
  12. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Jun 2011 Link to this post

    Hello Ram,

    HyperLinkColumn is accessed using its UniqueName property as shown below.

    aspx:
    <telerik:GridHyperLinkColumn DataTextField="Name" DataNavigateUrlFields="Name" UniqueName="HyperLinkColumn">  
    </telerik:GridHyperLinkColumn>

    Thanks,
    Shinu.
  13. Ram
    Ram avatar
    97 posts
    Member since:
    Jun 2011

    Posted 30 Jun 2011 Link to this post

    Ya. Its Working well.
    Thank you very much for ur reply. shine.
  14. Ram
    Ram avatar
    97 posts
    Member since:
    Jun 2011

    Posted 30 Jun 2011 Link to this post

    Hi
    Shinu.
    Cloud know me how to change foreclor of hyperlinkcolumn text(item) when user clicks.
    And its should retain default color when user clicks another item.
    Only selected hyperlink should have the color.
    I'm able to set row back color but I need to change the row item forecolor
    I think u got my problem
  15. Jhess
    Jhess avatar
    4 posts
    Member since:
    Aug 2011

    Posted 01 Sep 2011 Link to this post

    Hi Pincy,

    I have same problem with Mohammed, i have field that contains a link path to a PDF file, do you have a code behind for this on how to download the PDF using the hyperlink column, Thank you very much.

    Regards,
    Jhess
  16. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Sep 2011 Link to this post

    Hello Jhess,
    Try the following markup which gives the desired functionality.

    aspx:
    <telerik:GridHyperLinkColumn  DataNavigateUrlFields="Pdf Path" DataTextFormatString="Open {0}"  UniqueName="Name" DataNavigateUrlFormatString="\\server\share\{0}.doc"  DataTextField="Pdf Path">    
    </telerik:GridHyperLinkColumn>

    Thanks,
    Princy.
  17. Jhess
    Jhess avatar
    4 posts
    Member since:
    Aug 2011

    Posted 01 Sep 2011 Link to this post

    Thank you so much Princy, i owe you one.

    One more thing.. do you have any idea for downloading using GridAttachmentColumn, see below details where i got an error "
    Unable to cast object of type 'System.String' to type 'System.Byte[]'."

    Really sorry coz im new on this.

    WBPODFilename = varchar (file path is in C:\download folder
    ShipersCode = varchar



    <telerik:GridAttachmentColumn DataSourceID="SqlDataSource2" MaxFileSize="1048576"
      EditFormHeaderTextFormat="Upload File:" HeaderText="Download" AttachmentDataField="BinaryData"
      AttachmentKeyFields="MTR_ShipersCode" FileNameTextField="TRN_WBPODFilename" DataTextField="TRN_WBPODFilename"
      UniqueName="AttachmentColumn">
    </telerik:GridAttachmentColumn>

    codebehind:
     if (e.CommandName == RadGrid.DownloadAttachmentCommandName)
               {
                        e.Canceled = true;

                        GridDownloadAttachmentCommandEventArgs args = e as GridDownloadAttachmentCommandEventArgs;
                        string fileName = args.FileName;
                        string attachmentId = (string)args.AttachmentKeyValues["MTR_ShipersCode"];

                        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LMSConnectionString9"].ConnectionString);
                        SqlCommand comm = new SqlCommand("SELECT [TRN_WBPODFilename] FROM [VW_InqTran] WHERE [MTR_ShipersCode] = @MTR_ShipersCode", conn);
                        comm.Parameters.Add(new SqlParameter("@MTR_ShipersCode", attachmentId));

                        SqlDataAdapter adapter = new SqlDataAdapter(comm);
                        DataSet data = new DataSet();
                        adapter.Fill(data);

                        //   System.Text.Encoding enc = System.Text.Encoding.ASCII;
                        //  byte[] binaryData = enc.GetBytes("TRN_WBPODFilename");
                        // string myString = enc.GetString(binaryData);


                        //byte[] binaryData = System.Text.Encoding.Unicode.GetBytes(data.Tables[0].Rows[0]["TRN_WBPODFilename"].ToString());

                        byte[] binaryData = (byte[])data.Tables[0].Rows[0]["TRN_WBPODFilename"];
                        //byte[] binaryData = (byte[])data.Tables[0].Rows[0]["TRN_WBPODFilename"];
                        Response.Clear();
                        Response.ContentType = "application/octet-stream";
                        Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
                        Response.BinaryWrite(binaryData);
                        Response.End();
                }


    Thanks,
    Jhess

  18. saravanan k
    saravanan k avatar
    88 posts
    Member since:
    Mar 2010

    Posted 13 Mar 2013 Link to this post

    Hi Princy,

    Thanks. This solution opens the file in the browser window and allows the user to view it. However can you please provide a code that will pop up the open, save, cancel dialog box on click of the Hyperlink column?

    Thanks
    Saravanan K
  19. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Mar 2013 Link to this post

    Hi,

    Try the following code to achieve your scenario.
    C#:
    void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                HyperLink link = (HyperLink)item["HyperLinkColumn"].Controls[0];
                link.Attributes.Add("onclick", "test(); return false;");
           }
    }
    JS:
    function Validate()
     {
             radconfirm("Do you want to save?");
     }

    Thanks,
    Princy
  20. Ralph
    Ralph avatar
    2 posts
    Member since:
    Nov 2014

    Posted 11 Nov 2014 in reply to Princy Link to this post

    How can i open another radgid on clink of a link in my current radgrid?
  21. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 14 Nov 2014 Link to this post

    Hello Ralph,

    Could you specify how you expect the grid to open on click of a link - on window open or from user control?

    Regards,
    Pavlina
    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.

     
  22. Mubarak
    Mubarak avatar
    1 posts
    Member since:
    Aug 2014

    Posted 03 Feb Link to this post

    Am having a similar problem, but i want to access the pdf file a file part in my server here is my hyperlinkcolumn:

    <telerik:GridHyperLinkColumn DataTextField="uploaded_document" DataNavigateUrlFields="PDF" DataTextFormatString="Open {0}" DataNavigateUrlFormatString="/file" Target="_new" FilterControlAltText="Filter uploaded_document column" HeaderText="uploaded_document" SortExpression="uploaded_document" UniqueName="uploaded_document">
                    </telerik:GridHyperLinkColumn>

     

    and here is my code behind were am saving the data to a file, but i need to access it and view it on a new web browser

     

     protected void btnSaveDoc_Click(object sender, EventArgs e)
            {


                SqlConnection connarch = new SqlConnection("Data Source=localhost;Initial Catalog=NafArchive_db;Integrated Security=True");
                {
                    // Check File is selected into the file uploaad
                    if (FUploadDocFile.HasFile)
                    {



                        //byte[] docName = System.IO.File.ReadAllBytes(FUploadDocFile);
                        string extension = System.IO.Path.GetExtension(FUploadDocFile.FileName);

                        if (extension == ".pdf" || extension == ".jpg" || extension == ".docx" || extension == ".dot" || extension == ".mp4" || extension == ".wmv" || extension == ".ppt" || extension == ".pptx" || extension == ".docx" || extension == ".xlsx" || extension == ".xls")
                        {
                            // Get the folder path
                            string path = Server.MapPath("files\\");

                            string docName = guid + FUploadDocFile.FileName;
                            //Save Image
                            FUploadDocFile.SaveAs(path + docName);
                            LabelUploadChecker.Text = "File successfully saved...";
                            //SqlCommand cmd = new SqlCommand("sp_InsertFile", connarch);
                            SqlCommand cmdarch = new SqlCommand("Insert Into Documents(doc_number, doc_subject, doc_classification, doc_date, uploaded_document) VALUES(@doc_number, @doc_subject, @doc_classification, @doc_date, @uploaded_document)", connarch);

                            cmdarch.CommandType = CommandType.Text;
                            cmdarch.Parameters.AddWithValue("@doc_number", txtDocumentNo.Text);
                            cmdarch.Parameters.AddWithValue("@doc_subject", txtDocSubject.Text);
                            cmdarch.Parameters.AddWithValue("@doc_classification", ddlDocSyClass.Text);
                            cmdarch.Parameters.AddWithValue("@doc_date", txtDocDate.SelectedDate);
                            cmdarch.Parameters.AddWithValue("@uploaded_document", docName);
                            //cmd.CommandType = CommandType.StoredProcedure;


                            connarch.Open();
                            cmdarch.ExecuteNonQuery();

                            int result = cmdarch.ExecuteNonQuery();

                            if (result > 0)
                            {
                                LabelUploadChecker.Text = "Image uploaded to database...";
                            }

                            connarch.Close();

                            //txtDocSource.Text = "";
                            //txtDocSubject.Text = "";
                            //txtDocType.Text = "";
                            //txtDocumentNo.Text = "";
                            //txtDocVolume.Text = "";


                        }
                            else
                            {
                                LabelUploadChecker.Text = "File not in the required format...";
                            }
                        }
                        else
                        {
                            LabelUploadChecker.Text = "Please select document to be uploaded";
                        }


                    }

                }

     

     

     

    Thank you

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017