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. Advertisements

  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. Advertisements

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,808
    Fernando Lopes
    Dec 8, 2004
  2. sck10
    Replies:
    3
    Views:
    16,675
    techstuffbc
    Aug 19, 2009
  3. lupina
    Replies:
    3
    Views:
    27,415
    =?Utf-8?B?RWx0b24gVw==?=
    Mar 1, 2006
  4. =?Utf-8?B?Y2xpY2tvbg==?=

    Update Databound controls within a DetailsView TemplateField

    =?Utf-8?B?Y2xpY2tvbg==?=, Mar 23, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    7,121
    =?Utf-8?B?Y2xpY2tvbg==?=
    Mar 23, 2006
  5. sloan
    Replies:
    2
    Views:
    5,108
    aryan_subhash
    Oct 17, 2007
  6. mesut
    Replies:
    0
    Views:
    779
    mesut
    Jun 29, 2007
  7. pbd22
    Replies:
    0
    Views:
    735
    pbd22
    Oct 28, 2007
  8. Sharon

    Dynamic Templatefield problem gridview c#

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