Hi
In amazonLink it is showing Url but value in below line is NULL
HyperLink lnkAmazonLink = (HyperLink)e.Row.FindControl("AmazonURL");
In Table Header it is shown like this
Code
BookIdBookComboBookNameCoreRPLLexileNumberOfPagesSessionPlanStatusClosingStockAmazonURLHritvi Srini RemarksC#
string amazonLink = DataBinder.Eval(e.Row.DataItem, "AmazonURL").ToString().Trim();
if (amazonLink != null)
{
HyperLink lnkAmazonLink = (HyperLink)e.Row.FindControl("AmazonURL");
//lnkAmazonLink.Text = "Amazon Link";
//lnkAmazonLink.NavigateUrl = amazonLink;
//lnkAmazonLink.Target = "_blank";
////////lnkAmazonLink.CssClass = "amazon-link";
}Code
Thanks

Riddhi ValechaRank #794 · 2.9K reputationPosted May 23, 2023, 4:18 PM EDT
Hi..
Could you share the code in zip file please ?
It will be easy for us to debug.
Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted May 21, 2023, 8:02 AM EDT
Hi Ramco
Can you try these troubleshootings
Ensure that the field "AmazonURL" is present in the data source that is bound to the GridView.
Debug and inspect the data source and check if the "AmazonURL" field has a value for the corresponding row.
Verify that the field name is correct and there are no spelling or case sensitivity issues.
If the issue persists and the "AmazonURL" value is indeed NULL or not being retrieved correctly from the data source, you should investigate the data binding process, such as how the GridView is populated and how the data source is assigned.
Additionally, please note that in the code snippet, you have commented out the lines that set the properties of the HyperLink control (
lnkAmazonLink.Text,lnkAmazonLink.NavigateUrl,lnkAmazonLink.Target). Make sure to uncomment and modify these lines appropriately once the issue with retrieving the "AmazonURL" value is resolved.Tuhin PaulRank #7 · 71.9K reputationPosted May 21, 2023, 12:16 PM EDT
Part 1
The reason why the value of the AmazonURL control is NULL is because the AmazonURL column is not being populated in the data source. To fix this, you need to make sure that the AmazonURL column is being populated in the data source. You can do this by adding the AmazonURL column to the SELECT statement that is used to populate the data source.
Once you have added the AmazonURL column to the SELECT statement, you need to refresh the data in the GridView. You can do this by calling the GridView.DataBind() method.
Once you have refreshed the data in the GridView, the value of the AmazonURL control should no longer be NULL.
Tuhin PaulRank #7 · 71.9K reputationPosted May 21, 2023, 12:16 PM EDT
Part 2
Here is an example of how to add the AmazonURL column to the SELECT statement and refresh the data in the GridView:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string amazonLink = DataBinder.Eval(e.Row.DataItem, "AmazonURL").ToString().Trim(); if (amazonLink != null) { HyperLink lnkAmazonLink = (HyperLink)e.Row.FindControl("AmazonURL"); lnkAmazonLink.Text = "Amazon Link"; lnkAmazonLink.NavigateUrl = amazonLink; lnkAmazonLink.Target = "_blank"; lnkAmazonLink.CssClass = "amazon-link"; } } } protected void Page_Load(object sender, EventArgs e) { string sql = "SELECT BookId, Book, ComboBookName, CoreRPL, Lexile, NumberOfPages, SessionPlanStatus, ClosingStock, AmazonURL FROM tblBooks"; DataSet ds = new DataSet(); ds.ReadXml(sql); GridView1.DataSource = ds; GridView1.DataBind(); }