DataGrid extending with new/insert button

M

Manuel Trunk

Hi,
I try to develop a server control which inherits from DataGrid and adds a
new/insert button to this grid. This is no problem, but I can't get the event
fired from this new button.
I tried everything, implementing INamingContainer and IPostBackDataHandler,
added the button to the footer of the datagrid and so on. Nothing works.
Anyone who can help me?

Kind regrads,
Manuel
 
W

Wolfgang Schwedhelm

Hi Manuel!

I solved the same Problem.
There is a LinkButton in the second column in the footer.
Try:

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
DGDataBind();
}
else
{
Table tmp = (Table)DataGrid1.Controls[0];
LinkButton btn = (LinkButton)tmp.Rows[tmp.Rows.Count -
1].Cells[1].Controls[1];
btn.Click += new System.EventHandler(this.cmdAddNew_Click);
}
}
private void cmdAddNew_Click(object sender, System.EventArgs e)
{
//Your Event Code
}
private void DGDataBind()
{
//Your Binding Code
}

Wolfgang
 

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

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top