Dynamic TemplateField

S

Stan SR

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
 
S

Stan SR

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
 

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

Top