PushButton button column fails to select

S

Steve Trandahl

I added a Select button column to my datagrid. Everything works as expected
when I leave it at the default LinkButton button type. When I change it to a
PushButton button type, it no longer works. If I put a breakpoint in the
ItemCommand handler, it triggers for the LinkButton, but not the PushButton.

Am I doing something wrong? I am using Visual Studio 2003 on Windows XP.
 
M

MEG_

Add a CommandName to the push button in HTML:
i.e
<asp:ButtonColumn Text="Select" ButtonType="PushButton" HeaderText="Select"
CommandName="Select"></asp:ButtonColumn>

In C# you can do:
Add a new event handler to your DataGrid:

this.DataGrid1.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);


and the text of the function will be something like:
private void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e)
{
DataGridItem item = e.Item;
string Command = "";
try
{
Command = ((Button) e.CommandSource).CommandName;
}
catch {}

// only handle the command name you indicated above ....
if ((Command.Length == 0) ||
(Command.CompareTo("Select") != 0) )
{
return;
}
/// put the code to handle your select button here .....
 
S

Steve Trandahl

Most of the code you supplied is created by default when you choose the
"Select" Button Column. I did try adding an ItemCommand handler, but for some
reason it doesn't trigger for the PushButton. It does trigger for the
LinkButton. As far as I can tell, the only difference in the code is the
value of the ButtonType property.

Is anyone else experiencing this problem? Or does the PushButton select work
the same as the LinkButton.

Thanks,
Steve
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top