How do I add hyperlink to Item template column

Discussion in 'ASP .Net Web Controls' started by Reetu, Jul 17, 2003.

  1. Reetu

    Reetu Guest

    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
     
    Reetu, Jul 17, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?V2FyYW4=?=

    HyperLink Column and Button Column in a DataGrid

    =?Utf-8?B?V2FyYW4=?=, Aug 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    626
    =?Utf-8?B?V2FyYW4=?=
    Aug 9, 2005
  2. =?Utf-8?B?ZGF2aWQ=?=
    Replies:
    11
    Views:
    1,028
    deandany
    Jul 17, 2006
  3. davetichenor
    Replies:
    1
    Views:
    907
    Eliyahu Goldin
    Oct 30, 2006
  4. Keith G Hicks
    Replies:
    3
    Views:
    803
    Keith G Hicks
    Feb 18, 2008
  5. Dave
    Replies:
    0
    Views:
    997
Loading...

Share This Page