Composite Control not receiving DataGrid (child control) events?

D

debartsa

Hi Everybody,


I have a composite control (CompositeControl) which uses an instance of the
DataGrid (DataCtrl1) as a child control.
The DataGrid is dynamically created in the CreateChildControls() method of
my control and is responsible for rendering a list of web sites. The
DataGrid also generates an "Edit" push button alongside each of the list of
names (which will eventually be used for editing the list of items).

Everything works fine! the DataGrid does the work of rendering the list of
names and the "Edit" button as expected. My stumbling block occurs the
"Edit" button is clicked, for some reason the EditCommand event of the
DataGrid isn't firing? Does it have something to do with the .aspx page
consuming the control and the fact that the button click occurs during
postback?

My code ...

// CompositeControl.cs
//
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Diagnostics;

namespace AMT.Portal.Controls {

/// <summary>
/// My Compoiste control which dynamically creates a DataGrid
(DataCtrl1)
/// </summary>

public class CompositeControl : WebControl, INamingContainer
{

protected System.Web.UI.WebControls.DataGrid DataCtrl1;
protected System.Collections.Hashtable myTeamLinks;

protected override void CreateChildControls() {

Controls.Clear();
DataCtrl1 = new DataGrid();
DataCtrl1.AutoGenerateColumns = false;

BoundColumn col = new BoundColumn();
col.HeaderText = "Key";
col.DataField = "Key";

DataCtrl1.Columns.Add(col);

EditCommandColumn EditCol = new EditCommandColumn();
EditCol.EditText = "Edit";
EditCol.UpdateText = "Update";
EditCol.CancelText = "Cancel";
EditCol.ButtonType = ButtonColumnType.PushButton;

DataCtrl1.Columns.Add(EditCol);

DataCtrl1.DataSource = GetLinks();
DataCtrl1.DataBind();
Controls.Add(DataCtrl1);

this.DataCtrl1.EditCommand += new
DataGridCommandEventHandler(this.myDataGrid_EditCommand);

}

/// <summary>
/// Returns an IEnumerable type for the DataGrid to Bind
/// </summary>

private Hashtable GetLinks() {
myTeamLinks = new Hashtable();
myTeamLinks.Add("Microsoft Site", "http://www.microsoft.com");
myTeamLinks.Add("IBM Site", "http://www.ibm.com");
myTeamLinks.Add("Compaq", "http://www.hp.com");
myTeamLinks.Add("Google Site", "http://www.google.com");

return myTeamLinks;
}


/// <summary>
/// The Event Handler that isn't being called when the Edit button
of the DataGrid (Child Control) is clicked ?
/// </summary>

protected void myDataGrid_EditCommand(object sender,
DataGridCommandEventArgs e)
{
Trace.Write("The Data Grid EditCommand Event was fired");
}


Thanks for any help!
Sam
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top