I have an issue hope someone can help.
I have a dynamic Gridview
. I need to have a hyperlink
on gridview column. These hyperlink should open a popup to display certain data on clicking.
I tried this by having a dynamic template field . But even on binding the data , I'm unable to get the hyper link for the column. I'm able to get the data but not the hyperlink.
This is the HyperLinkTemplate
class which is implementing ITemplate
.
public class HyperLinkTemplate : ITemplate
{
private string m_ColumnName;
public string ColumnName
{
get { return m_ColumnName; }
set { m_ColumnName = value; }
}
public HyperLinkTemplate()
{
//
// TODO: Add constructor logic here
//
}
public HyperLinkTemplate(string ColumnName)
{
this.ColumnName = ColumnName;
}
public void InstantiateIn(System.Web.UI.Control ThisColumn)
{
HyperLink HyperLinkItem = new HyperLink();
HyperLinkItem.ID = "hl" + ColumnName;
HyperLinkItem.DataBinding += HyperLinkItem_DataBinding;
ThisColumn.Controls.Add(HyperLinkItem);
}
private void HyperLinkItem_DataBinding(object sender, EventArgs e)
{
HyperLink HyperLinkItem = (HyperLink)sender;
GridViewRow CurrentRow = (GridViewRow)HyperLinkItem.NamingContainer;
object CurrentDataItem = DataBinder.Eval(CurrentRow.DataItem, ColumnName);
HyperLinkItem.Text = CurrentDataItem.ToString();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…