Hi
I have below gridview in which there is one column Amazon Link. I want to be displayed as Amazon Link & when clicked it should open in another window
C#
SQLUtility sQLUtility = new SQLUtility();
DataTable dt = sQLUtility.GeBookPlanningRecommendation(HRpl, BookCollection, StudentCollection).Tables[0];
if (dt != null)
{
DataColumn Remarks = new DataColumn("Remarks", typeof(string));
dt.Columns.Add(Remarks);
grdPlanning.DataSource = dt;
grdPlanning.DataBind();
}Code
Thanks

Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted May 21, 2023, 2:41 AM EDT
To display short description alone kindly check this code
.amazon-link { color: blue; text-decoration: underline; cursor: pointer; }protected void gr_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string amazonLink = (string)DataBinder.Eval(e.Row.DataItem, "AmazonLink"); HyperLink lnkAmazonLink = (HyperLink)e.Row.FindControl("lnkAmazonLink"); lnkAmazonLink.Text = "Click here for Amazon"; // Set your desired link text lnkAmazonLink.NavigateUrl = amazonLink; lnkAmazonLink.Target = "_blank"; lnkAmazonLink.CssClass = "amazon-link"; } }In this updated code, yOu cann use a BoundField to display the "AmazonLink" column directly.
Ramco RamcoRank #462 · 5.4K reputationPosted May 21, 2023, 3:05 AM EDT
Hi Mohamed
I have autogeneratecolumns = true
Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted May 21, 2023, 2:23 AM EDT
Hi Mohammed
If i just want to display short description then what should be done.
Thank
Tuhin PaulRank #7 · 71.9K reputationPosted May 21, 2023, 12:43 PM EDT
To optimize the code, you can use a TemplateField instead of a BoundField to have more control over the display of the "AmazonLink" column. Here's an optimized version of the code:
CSS:
.amazon-link { color: blue; text-decoration: underline; cursor: pointer; }C#:
protected void grdPlanning_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { HyperLink lnkAmazonLink = (HyperLink)e.Row.FindControl("lnkAmazonLink"); lnkAmazonLink.CssClass = "amazon-link"; } }In this optimized version, we replaced the BoundField with a TemplateField and directly added an anchor tag (``) within the ItemTemplate. This allows you to customize the link text and navigate URL directly in the markup. The C# code remains the same, but I changed the event handler name to match the event name in the markup (`grdPlanning_RowDataBound`). Additionally, we only need to set the CSS class for the link in the RowDataBound event handler.
Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted May 21, 2023, 2:15 AM EDT
Hi Ramco to open amazon tan in another window in gridview try this code
' NavigateUrl='' Target="_blank">Hope this helps
Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted May 21, 2023, 3:25 AM EDT
Great