473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

[ASP.Net] Datagrid generic user control and DataGridCommandEventHandler

sda
Hi everybody,

I have a problem to fire an event in a DataGrid.

1/ I have got a datagrid in a generic user control

protected System.Web.UI.WebControls.DataGrid dgListDataGrid;
........

public void ListDataGridDataBind()
{
.... my databind function
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
ListDataGridDataBind();
}

2/ My Datagrid has a programmatically defined template column with
ImageButton

class myModifyTemplateColumn : ITemplate
{
string _sColumnName = "";
string _sId = "";
//public event DataGridCommandEventHandler myImageCommand;

public myModifyTemplateColumn(string sColumnName, string sId)
{
_sColumnName = sColumnName;
_sId = sId;
}
public void InstantiateIn(Control container)
{
ImageButton ib = new ImageButton();
ib.DataBinding += new EventHandler(this.BindImageButtonColumn);
container.Controls.Add(ib);
}
public void BindImageButtonColumn(object sender, System.EventArgs e)
{
ImageButton ib = (ImageButton) sender;
DataGridItem container = (DataGridItem) ib.NamingContainer;
ib.ID = _sColumnName + _sId;
ib.EnableViewState = true;
ib.CausesValidation = false;
ib.CommandArgument =
Convert.ToString(DataBinder.Eval(container.DataIte m, _sId));
ib.CommandName = Convert.ToString(DataBinder.Eval(container.DataIte m,
_sColumnName));
ib.ImageUrl = Convert.ToString(DataBinder.Eval(container.DataIte m,
_sColumnName));
}
}

3/ My Generic User Control contain a public event :

public event DataGridCommandEventHandler ListDataGridCommand;

4/ My Generic User Control in the Page_Init create the new event :

this.dgListDataGrid.ItemCommand += this.ListDataGridCommand; //
(dgListDataGrid : the grid)

5/ I use this datagrid in several others user controls
In ascx :

<uc1:ListDataGrid id="ucListDataGrid" runat="server"></uc1:ListDataGrid>

In ascx.cs :

ucListDataGrid.ListDataGridDataSource = oMain.Service.ListeDesEtapes();
ucListDataGrid.ListDataGridCommand += new
DataGridCommandEventHandler(ucListDataGrid_ListDat aGridImageCommand);
ucListDataGrid.ListDataGridDataBind();

and

private void ucListDataGrid_ListDataGridImageCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Response.Write("Fire : ucListDataGrid_ListDataGridImageCommand");
}

Never my ImageButton event is fired !!!
Any suggestions ?

Thanks

Best regards
SDA

Nov 19 '05 #1
0 1120

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fortra | last post by:
I'm having trouble with the UpdateCommand event with the DataGrid control. The event is wired up in the InitializeComponents properly, this.sitesDataGrid.UpdateCommand += new...
2
by: Martin Hazell | last post by:
For various reasons, I have had to produce a quick (!) page to edit one column of data in a database with ASP.net. With this being my first foray into ASP.net, I apoligise for any basic erros I have...
3
by: Li Zhang | last post by:
I have a user control contain one datagrid. this datagrid contains one button column with commandName "Review", I have event handler datagrid_ItemCommand to handle this event and also wired the...
0
by: zhaoJian | last post by:
Here it is my code ,but it can't update the database.How to do it ? In _UpdateUnit event, I can not get the original value to @Original_UnitID,so I set a hidden column named LabelKey.But It...
0
by: Steve | last post by:
I have a datagrid that is created at run time DataGrid dgG = new DataGrid(); BoundColumn bcB; dgG.CellPadding = 5; dgG.CellSpacing = 0; dgG.GridLines = GridLines.Both; dgG.CssClass =...
1
by: benoit | last post by:
Hi, I created a Dynamic Datagrid and i added an EditCommandColumn to it. Works fine, but my Editcommand eventhandler seems to have a problem with PostBack This is my code private DataGrid...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
0
by: arlie_maija | last post by:
Hey - I'm writing a control that contains a DataGrid, and I'm unable to get the update event to fire. When I click the update link, the edit event fires. heres the details... my control...
0
by: shamirza | last post by:
· What is view state and use of it? The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.