3
Reply

how do I add a linkbutton to a gridview at runtime?

Kent

Kent

Apr 30 2009 11:27 AM
11.8k

I build a gridview at runtime that works great.  Now, I have to add a linkbutton to the gridview at runtime (the linkbutton will allow display a modal popup for editing).  The code below is not working.  I use similar code to add an imagecontrol to the gridview and it works.  Can anyone help?

// Add the edit link
TemplateField tfEdit = new TemplateField();
tfEdit.ShowHeader = false;
LinkButton lb = new LinkButton();
lb.ID = "lnkEditProduct";
lb.Text = "Edit Item";
lb.CommandArgument = "<%# Bind('itemID') %>";
lb.CommandName = "EditProduct";
lb.CausesValidation = false;
gvResults.Columns.Add(lb);

Thank you!


Answers (3)