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
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.
Could you send the code snippet how to do it in the code behind.
Thanks,
Dwarak
Thanks for the post.
Thanks
Dwarak
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.
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
Thank you so much Princy, it worded.
Regards,
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.
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.
But I'm getting "Cannot find a cell bound to column name 'HyperLinkColumn'" error in databound event.
can u pls verify
HyperLinkColumn is accessed using its UniqueName property as shown below.
aspx:
<
telerik:GridHyperLinkColumn
DataTextField
=
"Name"
DataNavigateUrlFields
=
"Name"
UniqueName
=
"HyperLinkColumn"
>
</
telerik:GridHyperLinkColumn
>
Thanks,
Shinu.
Thank you very much for ur reply. shine.
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
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
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.
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
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
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;"
);
}
}
function
Validate()
{
radconfirm(
"Do you want to save?"
);
}
Thanks,
Princy
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.
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