Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Button.Click not raised in Gridview's Template column

Reply
Thread Tools

Button.Click not raised in Gridview's Template column

 
 
SEliel@gmail.com
Guest
Posts: n/a
 
      05-30-2007
Hello everyone:

I'm programming a custom GridView, adding column by column
dynamically. Every column is a TemplateField, and I've made a class
hierarchy for each template (TextColumnTemplate,
DropDownListColumnTemplate, ButtonColumnTemplate), implementing
ITemplate.

The problem is in ButtonColumnTemplate. Here's is my code:

public class GridViewButtonTemplate : GridViewTemplate
{
private string command;

public string Command
{
set { this.command = value != null ? value : ""; }
}

public GridViewButtonTemplate(DataControlRowType type, string
columnName, string command)
{
this.templateType = type;
this.columnName = columnName;
this.command = command;
}

public GridViewButtonTemplate(DataControlRowType type, string
columnName, string command, EventHandler cmd)
{
this.templateType = type;
this.columnName = columnName;
this.command = command;
this.cmd = cmd;
}

public override void InstantiateIn(Control container)
{
Button btn = new Button();
switch (templateType)
{
case DataControlRowType.Header:
Literal lc = new Literal();
lc.Text = "<b>" + text + "</b>";
container.Controls.Add(lc);
break;
case DataControlRowType.DataRow:
btn.Text = this.command;
btn.DataBinding += new EventHandler(this.DataBinding);
btn.Click += new EventHandler(this.BtnClicked);
btn.CausesValidation = false;
btn.UseSubmitBehavior = true;
container.Controls.Add(btn);
break;
}

}

protected override void DataBinding(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
string raw = DataBinder.Eval(gvr.DataItem,
columnName).ToString();
btn.CommandArgument = (raw != null && raw != "") ? raw : "";
}

public void BtnClicked(object sender, EventArgs e)
{
// Expected behavior for button's click event
}

}

As you can see, I'm adding correctly the respective event to each
event handler of the controls. The DataBinding is working well, and
everything is displayed as i wanted, but when i click a button from de
ButtonColumn, there's no responding from the server... Any ideas?

(excuse me if my English is not so good, i'm from Mexico)

Thanks in advice

 
Reply With Quote
 
 
 
 
Andy
Guest
Posts: n/a
 
      05-30-2007
ASP.NET buttons actually have two change handlers: one for clicks, and
the other for commands.

Could it be that you have setup only the command handler and not the
click handler for the button, and this is why you are not getting any
responses?

 
Reply With Quote
 
 
 
 
SEliel@gmail.com
Guest
Posts: n/a
 
      05-30-2007
Yes, i know that. I've tried with EventHandler for Click event, and
CommandEventHandler for Command event (setting up button's CommandName
and CommandArguments properties in method InstantiateIn), and in both
cases i have no response from the server when button is clicked.

Perhaps is something about GridView events, but i've read that one of
the major improvements of GridView over DataGrid is that one event is
raised in the control, no in the cell containing controls...

 
Reply With Quote
 
SEliel@gmail.com
Guest
Posts: n/a
 
      05-30-2007
I tried to say "Thanks in advance" in the first post, excuses :S.

 
Reply With Quote
 
SEliel@gmail.com
Guest
Posts: n/a
 
      05-30-2007
Well, while i'm waiting an idea, i've was making other thing related
to the gridview...

Since all the columns are displayed in edit mode, there must be a
button that take all the changes made to the data displayed in the
gridview, and i discovered that all gridview's information (columns,
rows, etc.) has gone.

Of course the gridview's datasource/databind executes in !IsPostBack
segment of the code... so i think that's the cause of column button is
not raising the event, because it doesn't exists anymore...

Any ideas?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
setting Column width of Template Column in Datagrid.. Charleees ASP .Net 2 06-20-2006 12:52 PM
DataGrid loses view state if first column is a template column. Ken Varn ASP .Net 1 08-19-2005 02:54 PM
Template column base on another column value Esperanza ASP .Net Datagrid Control 5 02-21-2005 04:02 PM
how to know if a datagrid column is a template column? Dexter ASP .Net 1 01-18-2005 01:45 PM
Bound Column or Template Column (w dAdapater?) in DataGrid Ravichandran Mahalingam ASP .Net Datagrid Control 0 01-09-2004 03:30 PM



Advertisments