Dynamic TemplateField

Discussion in 'ASP .Net' started by Stan SR, Jun 16, 2007.

  1. Stan SR

    Stan SR Guest

    Hi,

    How can I convert this in c# code ?

    <asp:TemplateField HeaderStyle="100">
    <ItemTemplate>
    <a href="#" onclick="<%#funcDelete(Container.DataItem)%>">Delete</a>
    </ItemTemplate>
    </asp:TemplateField>

    Thanks in advance.

    Stan
     
    Stan SR, Jun 16, 2007
    #1
    1. Advertising

  2. Stan SR

    Stan SR Guest

    That's okay, It's done..

    Here's what I code.
    I don't know if I could optimize this..

    public class gTemplate : ITemplate
    {
    public gTemplate(){}
    public InstantiateIn(System.Web.Ui.Control.container)
    {
    Literal myLnk= new Literal();
    myLnk.DataBinding+=new EventHandler(this.Id_DataBinding);
    container.Controls.Add(myLnk);
    }
    private void Id_DataBinding(Object sender, EventArgs e)
    {
    Literal myLiteral = (myLiteral) sender;
    GridViewRow myRow (GridViewRow) myLiteral.NaminContainer;
    myLiteral="<a href=\"#\" onclick="myFunction('"+
    DataBinder.Eval(myRow.DataItem,"Id").ToString()+"')\">Delete</a>";
    }
    }


    And I add to the gridview

    TemplateField myTemplate=newTemplateField();
    myTemplate.ItemStyle.Width=100;
    myTemplate.ItemTemplate=new gTemplate();
    myGridView.Columns.Add(myTemplate);

    Stan



    "Stan SR" <> a écrit dans le message de
    news:OuGcwo$...
    > Hi,
    >
    > How can I convert this in c# code ?
    >
    > <asp:TemplateField HeaderStyle="100">
    > <ItemTemplate>
    > <a href="#"
    > onclick="<%#funcDelete(Container.DataItem)%>">Delete</a>
    > </ItemTemplate>
    > </asp:TemplateField>
    >
    > Thanks in advance.
    >
    > Stan
     
    Stan SR, Jun 16, 2007
    #2
    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. Fernando Lopes
    Replies:
    0
    Views:
    5,704
    Fernando Lopes
    Dec 8, 2004
  2. sloan
    Replies:
    2
    Views:
    4,937
    aryan_subhash
    Oct 17, 2007
  3. mesut
    Replies:
    0
    Views:
    608
    mesut
    Jun 29, 2007
  4. pbd22
    Replies:
    0
    Views:
    617
    pbd22
    Oct 28, 2007
  5. Sharon

    Dynamic Templatefield problem gridview c#

    Sharon, Mar 16, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    344
    Sharon
    Mar 16, 2007
Loading...

Share This Page