How to determine which control in a template column was clicked...

J

Jim Mitchell

I have the following datagrid with two template columns. Can someone tell
he how I would know which "imgContacts1" was clicked and what the onclick
routine would look like in code behind?

In otherwords, how do you trap the onclick event for in image control in a
datagrid template?

Thanks in advance...

Jim

<Columns>
<asp:TemplateColumn HeaderText="Options1">
<HeaderTemplate>
Options
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton id="imgContacts1" runat="server"
ImageUrl="images/find.gif"></asp:ImageButton>
<asp:ImageButton id="imgContacts2" runat="server"
ImageUrl="images/folder.gif"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Options2">
<ItemTemplate>
<asp:ImageButton id="ImageButton3" runat="server"
ImageUrl="images/info.gif"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
 
T

Teemu Keiski

You could specify command name but different command arguments (respective
CommandName and CommandArgument properties) for the ImageButton. After this
you could handle DataGrid's ItemCommand event that is fired when controls
that have command event/command functionality are clicked.

In this case in the ItemCommand event the command name and argument of the
clicked ImageButton (specified as described in the previous paragraph) are
provided as event argument and from there you could know which button was
clicked. I.e just by comparing event argument that does they match for which
button.

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
 
J

Joel .NET

You have to use an ImageButton inside the template. Then you can use the
commandname, and commandargument properties in the ItemCommand event.

Joel
 

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,013
Latest member
KatriceSwa

Latest Threads

Top