DataGrid TemplateColumn and Events

D

DAC

I am creating a datagrid programatically and I successfuly coded a
TemplateColumn (that inherits from ITemplate and implements InstantiateIn).
I want to place an ImageButton there.

How do I:
1. Associate an event for the click on the button?
2. How do I know in which row the user clicked inside the event handler?

3. (out of context) Is it possible to code a rollover javascript code to
change the imgURL when the user leaves mouse over the image (as we did in
old ASP with some help from DreamWeaver)?

Thank you very much.
Daniel
 
S

Stevie_mac

I was looking to have a try at this (template columns), is there any chance you can post your ITemplate class & a SNIP
of how you instansiate a template col programatically? Any way, heres some info...
1. Associate an event for the click on the button?
btn.Click += new EventHandler (BtnTest_Click); //(C#)
AddHandler btn.Click, AddressOf MySubToHandleButtonClick '(VB)
2. How do I know in which row the user clicked inside the event handler?
In ItemCommand, check e.Item.ItemIndex
3. (out of context) Is it possible to code a rollover javascript code to
change the imgURL when the user leaves mouse over the image (as we did in
old ASP with some help from DreamWeaver)?
See this - http://www.dotnet247.com/247reference/msgs/12/61815.aspx


Good luck Stevie_mac
 
D

DAC

Here's my solution so far...
Notice I use an ImageButton.
----------------

public class DeleteColumnTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
ImageButton myImgButton = new ImageButton();
myImgButton.AlternateText = "Remove this row.";
myImgButton.ImageUrl = "img/remove.gif";
//myImgButton.Click += new
System.Web.UI.ImageClickEventHandler(DeleteItem_Click); ???????
container.Controls.Add(myImgButton);
}
}

..
..
..
// Instantiating:

TemplateColumn coledit = new TemplateColumn();
coledit.HeaderText = "Template";
coledit.ItemTemplate = new DeleteColumnTemplate();
coledit.ItemStyle.HorizontalAlign = HorizontalAlign.Center;

DataGrid1.Columns.Add(coledit);


----------------
Daniel

Stevie_mac said:
I was looking to have a try at this (template columns), is there any
chance you can post your ITemplate class & a SNIP
 
D

DAC

Stevie,

I get "Method 'DeleteItem_Click(object, System.Web.UI.ImageClickEventArgs)'
does not match delegate 'void System.EventHandler(object, System.EventArgs)'
"

when adding the event handler.

.... or... cannot convert from EventHandler to ImageClickEventHandler....

Any ideas?

Daniel


Stevie_mac said:
I was looking to have a try at this (template columns), is there any
chance you can post your ITemplate class & a SNIP
 
J

Jonas Karlsson

I solved this problem myself, but I am surprised that I couldn't find the
answer here...

The trick is to use
GridDays.EditCommand += new DataGridCommandEventHandler(GridDays_Edit);
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top