473,411 Members | 2,196 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,411 software developers and data experts.

Button.Click not raised in Gridview's Template column

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

May 30 '07 #1
4 7206
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?

May 30 '07 #2
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...

May 30 '07 #3
I tried to say "Thanks in advance" in the first post, excuses :S.

May 30 '07 #4
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?

May 30 '07 #5

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

Similar topics

3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
1
by: keithb | last post by:
I have a GridView control that has a delete button (hyperlink) in one column. The datasource table contains a column that has a true/false indicator showing whether or not the record can be...
0
by: =?Utf-8?B?Sm9l?= | last post by:
I have a gridview with buttons in a column and I want those buttons to be triggers for an update panel further down on the page. So for example, when a user clicks on the button in row 3, I want...
5
by: obs | last post by:
Hi. I have read a previous post in the subject, but could not find an answer, so my question is how do I find the SelectedIndex of a row in a gridview row where there is a command button ? The...
2
by: shapper | last post by:
Hello, I am working with a ListView but I suppose that with a GridView might be the same. Instead of having an Insert Button on each GridView row I would like to have only one Insert button,...
4
by: Ken Fine | last post by:
I'm making an administrative interface that lists records in a GridView. For *each* row in the gridview, I would there to be two interface elements in addition to some information associated with...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview with one of the columns as a template column with a button. When the user selects the button is there a way to get the row number in the button_Click event? Another one of...
0
by: Ty | last post by:
I have a page that has three gridviews on it. In each gridview the first column is a link button representing a Database ID field. What I'm trying to accomplish is to email that page and click on...
1
by: =?Utf-8?B?SkI=?= | last post by:
Hi, I have two buttons that are within the template field, of a gridview. The gridview is in a web control. I am able to deletage most of the events that the gridview fires, with the code...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.