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

radgrid hyperlink column

20 Answers 3801 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dwarak kanniah
Top achievements
Rank 1
dwarak kanniah asked on 23 Nov 2009, 07:04 AM
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

20 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Nov 2009, 07:36 AM
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.
0
dwarak kanniah
Top achievements
Rank 1
answered on 23 Nov 2009, 08:08 AM
Hi Princy,
            
           Could you send the code snippet how to do it in the code behind.

Thanks,
Dwarak

 
0
dwarak kanniah
Top achievements
Rank 1
answered on 23 Nov 2009, 10:32 AM
Hi Princy,

                Thanks for the post.

Thanks
Dwarak
0
Mohammed
Top achievements
Rank 1
answered on 05 Jun 2011, 08:51 AM
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.
0
Princy
Top achievements
Rank 2
answered on 06 Jun 2011, 07:50 AM
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
0
Mohammed
Top achievements
Rank 1
answered on 06 Jun 2011, 07:56 AM

Thank you so much Princy, it worded.


Regards,
0
Ram
Top achievements
Rank 1
answered on 30 Jun 2011, 07:08 AM
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.

0
Shinu
Top achievements
Rank 2
answered on 30 Jun 2011, 07:26 AM
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.
0
Ram
Top achievements
Rank 1
answered on 30 Jun 2011, 07:35 AM
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
0
Shinu
Top achievements
Rank 2
answered on 30 Jun 2011, 07:40 AM
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.
0
Ram
Top achievements
Rank 1
answered on 30 Jun 2011, 07:44 AM
Ya. Its Working well.
Thank you very much for ur reply. shine.
0
Ram
Top achievements
Rank 1
answered on 30 Jun 2011, 08:43 AM
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
0
Jhess
Top achievements
Rank 1
answered on 01 Sep 2011, 12:51 PM
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
0
Princy
Top achievements
Rank 2
answered on 01 Sep 2011, 01:59 PM
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.
0
Jhess
Top achievements
Rank 1
answered on 02 Sep 2011, 03:00 AM
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

0
saravanan k
Top achievements
Rank 1
answered on 13 Mar 2013, 06:47 AM
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
0
Princy
Top achievements
Rank 2
answered on 13 Mar 2013, 07:08 AM
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
0
Ralph
Top achievements
Rank 1
answered on 12 Nov 2014, 05:52 AM
How can i open another radgid on clink of a link in my current radgrid?
0
Pavlina
Telerik team
answered on 14 Nov 2014, 09:50 AM
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.

 
0
Mubarak
Top achievements
Rank 1
answered on 03 Feb 2016, 02:55 PM

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

 

Tags
Grid
Asked by
dwarak kanniah
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
dwarak kanniah
Top achievements
Rank 1
Mohammed
Top achievements
Rank 1
Ram
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Jhess
Top achievements
Rank 1
saravanan k
Top achievements
Rank 1
Ralph
Top achievements
Rank 1
Pavlina
Telerik team
Mubarak
Top achievements
Rank 1
Share this question
or