buttoncolumn doesn't fire event

N

nipe

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_ItemCommand);
....
}

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
 
T

Teemu Keiski

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.
 

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

Top