How do I add hyperlink to Item template column

R

Reetu

Hi,

I have been searching on how I could add hyperlink to
Item template column's data



Code in HTML mode

<ItemTemplate>
<asp:HyperLink NavigateUrl='<%# ShowTaskUrl
(Container.DataItem) %>' Runat=server>
%# GetTaskName(Container.DataItem) %>
</asp:HyperLink>
</ItemTemplate>

At present I have written the following code to retrieve
the value. I am able to get the data but I want it be a
hyperlink. I read few articles mentioning about
HyperlinkColumn. But I am still not clear on how I should
apply it to a template Column

//** TemplateColumn code displaying data without
hyperlink **//

TemplateColumn DynamicTaskItemTemplate = new TemplateColumn
();
DynamicTaskItemTemplate.HeaderText = "Task";
DynamicTaskItemTemplate.ItemTemplate = new
DynamicTaskItemTemplate();

// CODE of DynamictaskItemTemplate

public class DynamicTaskItemTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
Literal lc = new Literal();
lc.DataBinding += new EventHandler
(this.DoDataBinding);
container.Controls.Add(lc);
}

public void DoDataBinding(object sender, EventArgs e)
{
Literal lc = (Literal)sender;
DataGridItem container = (DataGridItem)
lc.NamingContainer;
DataRowView drv = (DataRowView)container.DataItem;
string name = (string)drv["Name"];
lc.Text = name;
}

}

Thanks
-Reetu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top