eventhandler of a programmatically created datagird

A

Anna Schmidt

Hello,

I have a programmatically created datagrid (no def in the aspx-file)


dg2.DataBind();
holder.Controls.Add(dg2); // placeholder


in the method InitializeComponent i want to add events (sorting paging) etc.
to this Datagrid dg2:

private void InitializeComponent()
{
this.dg2.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dg_Sort);
....}

but unfortunately it doesn't work..nothings happens? or sometimes VS deletes
this line

Any idea?

thank you

as
 
S

SB

Anna,

I already had that problem in the past, where indeed, VS removes the line
from the initializecomponent method.
An easy workaround is to call a method that initialize the events from
within the page_load method, and in that case, it is no longer removed by
VS.
EX:
void Page_Load(){
HookEventsOnControls();
}
private void HookEventsOnControls(){
this.dg2.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dg_Sort);
}
 

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,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top