473,396 Members | 1,815 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,396 software developers and data experts.

buttoncolumn doesn't fire event

Hello,
I'm having problem with my custom datagrid control can't fire
itemcommand event.
The fact is that I have to make fully cutom user control so I can't do
any scripting to .aspx file.
There are two classes that has something to do with this: datagrid
class which has 2 buttoncolumns and panel class that HAS datagrid and
handles itemcommand event.

//datagrid class is like this
public class MyDataGrid : DataGrid , INamingContainer
{
....
ButtonColumn brisiButCol = new ButtonColumn();
ButtonColumn saljiButCol = new ButtonColumn();

protected override void OnInit(EventArgs e)
{
Inicijalizuj();
base.OnInit(e);
}

private void Inicijalizuj()
{
this.AutoGenerateColumns = false;
....
brisiButCol.Text = "Brisi";
brisiButCol.CommandName = "Delete";
brisiButCol.ButtonType = ButtonColumnType.PushButton;

saljiButCol.Text = "Salji";
saljiButCol.CommandName = "Salji";
saljiButCol.ButtonType = ButtonColumnType.PushButton;
}

public void DodajKolone()
{
this.Columns.Add(col1);
this.Columns.Add(col2);
this.Columns.Add(col3);
this.Columns.Add(brisiButCol);
this.Columns.Add(saljiButCol);
}
}

//and the panel class is like this:

class FajloviPanel : Panel, INamingContainer
{
internal MyDataGrid fajloviDataGrid = new MyDataGrid();
.....

protected override void OnInit(EventArgs e)
{
InicijalizujKontrole();
base.OnInit(e);
}

private void InicijalizujKontrole()
{
fajloviDataGrid.ItemCommand += new
DataGridCommandEventHandler(fajloviDataGrid_ItemCo mmand);
....
}

protected override void CreateChildControls()
{
fajloviDataGrid.DodajKolone();
Controls.Add(fajloviDataGrid);
....
fajloviDataGrid.DataBind();

base.CreateChildControls();
}
}

Like I said, application naver gets into fajloviDataGrid_ItemCommand
method.

I'm sorry I don't have much experience in ASP.NET so maybe there is
some lame mistake, but I'm having troubles with this for a pretty long
time..
Any suggestion will help.
Thanks!
Nikola

Mar 9 '07 #1
1 1690
Hi,

you shouldn't DataBind() the child grid in CreateChildControls. Either wrap
access to the grid via properties in the Panel so that grid's dataSource can
be set and DataBind() called or (let user) call DataBind() on the Panel
straight, which actually recursively calls DataBind() for the grid as well
(DataSource needs to be set of course)

Calling dataBind() on CreateChildControls databings the grid on every
request and sort of prevents postback events from working.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"nipe" <ni****@gmail.comwrote in message
news:11**********************@c51g2000cwc.googlegr oups.com...
Hello,
I'm having problem with my custom datagrid control can't fire
itemcommand event.
The fact is that I have to make fully cutom user control so I can't do
any scripting to .aspx file.
There are two classes that has something to do with this: datagrid
class which has 2 buttoncolumns and panel class that HAS datagrid and
handles itemcommand event.

//datagrid class is like this
public class MyDataGrid : DataGrid , INamingContainer
{
...
ButtonColumn brisiButCol = new ButtonColumn();
ButtonColumn saljiButCol = new ButtonColumn();

protected override void OnInit(EventArgs e)
{
Inicijalizuj();
base.OnInit(e);
}

private void Inicijalizuj()
{
this.AutoGenerateColumns = false;
...
brisiButCol.Text = "Brisi";
brisiButCol.CommandName = "Delete";
brisiButCol.ButtonType = ButtonColumnType.PushButton;

saljiButCol.Text = "Salji";
saljiButCol.CommandName = "Salji";
saljiButCol.ButtonType = ButtonColumnType.PushButton;
}

public void DodajKolone()
{
this.Columns.Add(col1);
this.Columns.Add(col2);
this.Columns.Add(col3);
this.Columns.Add(brisiButCol);
this.Columns.Add(saljiButCol);
}
}

//and the panel class is like this:

class FajloviPanel : Panel, INamingContainer
{
internal MyDataGrid fajloviDataGrid = new MyDataGrid();
....

protected override void OnInit(EventArgs e)
{
InicijalizujKontrole();
base.OnInit(e);
}

private void InicijalizujKontrole()
{
fajloviDataGrid.ItemCommand += new
DataGridCommandEventHandler(fajloviDataGrid_ItemCo mmand);
...
}

protected override void CreateChildControls()
{
fajloviDataGrid.DodajKolone();
Controls.Add(fajloviDataGrid);
...
fajloviDataGrid.DataBind();

base.CreateChildControls();
}
}

Like I said, application naver gets into fajloviDataGrid_ItemCommand
method.

I'm sorry I don't have much experience in ASP.NET so maybe there is
some lame mistake, but I'm having troubles with this for a pretty long
time..
Any suggestion will help.
Thanks!
Nikola
Mar 9 '07 #2

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

Similar topics

0
by: Northern | last post by:
I am having problem select a row from datagrid. According to the doc, the standard way of doing this is to add ButtonColumn to the grid and have a event handler do the work. I added this...
3
by: John | last post by:
The ItemCommand event not getting fired when I add both a BoundColumn and a ButtonColumn to a datagrid. When I add a ButtonColumn by itself, everything works fine, but as soon as I add a...
2
by: Nick Gilbert | last post by:
We have a Datagrid which contains a template column with a button in it, as well as an actual button column. If either of the buttons are clicked, the ItemCommand event does not fire. If...
6
by: z. f. | last post by:
Hi, i have a datagrid with a delete button for each row in the grid. when the delete button is clicked i need to ask the user in a "confirm" message box if he's sure he wants to delete. the...
1
by: Phil Townsend | last post by:
I have placed a buttoncolumn into a datagrid, but it does not seem to raise any event when clicked. It should be firing the ItemCommand event, right? There is an appropriate event handler...
1
by: Lenin Sakthees via .NET 247 | last post by:
Hi all, I am using a datagrid to show values from a SQL table. My problem is, I want to show the details of the each row when the user clicks the 'View details' buttoncolumn. I am able to fire a...
6
by: Shimon Sim | last post by:
I have Panel control on the page. I am handling Init event for it. It doesn't seem to fire at all. Why? Thank you Shimon.
2
by: Hardy Wang | last post by:
Hi all, We have DataGrid control in Web Form, our client requires to be able to click anywhere of a row to fire the event same as LinkBotton column is clicked. We we did in ASP.NET 1.1 is in...
9
by: rn5a | last post by:
A DataGrid is populated with the records existing in a database. Each of the row in this DataGrid has a ButtonColumn. Assume that the DataGrid displays 10 records (i.e. 10 DataGridItems/rows). Each...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.