tags:

views:

20

answers:

1

Hi,

Custom events in a custom data bound control are not firing in DataRepeater control. When I debug it I found that the DataRepeater Control recreates the control using Activator.CreateInstance and Copies the Properties and Events. In my case copying events doesn't copy the custom events that I hooked in.

For example

public class MyClass : Control { public event EventHandler MyEvent;

protected virtual void OnMyEvent() { if(this.MyEvent != null) { this.MyEvent(this,EventArgs.Empty); } }

private int selectedIndex= -1; public int SelectedIndex { get { return this.selectedIndex; } set { if(this.selectedIndex != value) { this.selectedIndex = value; this.OnMyEvent(); } } } // // DataBinding stuff goes here //

}

public Form1() { InitialiseComponent();

ArrayList list = new ArrayList(); list.Add("one");

this.dataRepeater1.DataSource = list; // One Repeater

MyClass test = new Myclass(); test.DataSource = GetDataTable();

this.dataRepeater1.ItemTemplate.Controls.Add(test);

test.MyEvent +=new EventHandler(test_MyEvent);

}

// This Event should fire when selected index of Datatable is changed and is firing when placed directly in the form and not firing when place in DataRepeater control/////////////////////// private void test_MyEvent(object sender, EventArgss e) { // This event is not fired/////////////////////// }

private DataTable GetDataTable() { ..// Create a data Table and return }

Any help Appreciated.

Thanks,

A: 

Hi,

Please refer the below forums. It will helpful to you.

http://social.msdn.microsoft.com/Forums/en-US/vbpowerpacks/thread/b8b2bf93-46d5-406b-8947-c7b9ba02a771

Regards, Lingaraj S.