Solved

Capturing template button events in a datagrid???

Posted on 2004-04-20
3
941 Views
Last Modified: 2007-12-19
Hi all.
I created a web form with a datagrid and I added templates to the grid with custom image buttons for row edit, delete, update, and cancel actions.
But I have not been able to capture any events for those image buttons.
If I don't use the template buttons and just use grid default edit, update, cancel button column instead, then everything works fine with DataGrid_EditCommnad, DataGrid_UpdateCommand, and DataGrid_CancelCommand events handle procedures.
Is anyone able to explain how to capture events from those template image buttons.
Thanks.
0
Comment
Question by:soweyoung
  • 2
3 Comments
 
LVL 7

Expert Comment

by:dante469
ID: 10869541
Pressing the image button in the template column would be accessable as follows (example image button id is ibtnTemplateCol)....

---.ASPX---->
<asp:ImageButton id="ibtnTemplateCol" runat="server" ImageUrl="http://www.experts-exchange.com/images/vipAccess.gif" OnClick="ibtnTemplateCol_C"></asp:ImageButton>

---Codebehind---->  'Notice the sub is NOT private
Sub ibtnTemplateCol_C(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Dim sWorld As String = "From iButton in Template Column"
        Response.Write(sWorld)
End Sub

Have fun,
Dante
0
 
LVL 20

Accepted Solution

by:
ihenry earned 125 total points
ID: 10869890
using ItemCommand event,

--- ASPX ---
<asp:datagrid AutoGenerateColumns="False" >
<Columns>
     <asp:TemplateColumn>
          <ItemTemplate>
               <asp:ImageButton AlternateText="Delete this item" CausesValidation="False" CommandName="Delete" ImageUrl="~/images/delete.gif" Runat="server"></asp:ImageButton>
          </ItemTemplate>
     </asp:TemplateColumn>
</Columns>
</asp:datagrid>

--- ASPX.VB --
Sub DataGrid1_ItemCommand( sender As Object, e As DataGridCommandEventArgs )

     If ( e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem )

          If ( e.CommandName = "Delete ")
               ' the image button is pressed..
          End If

     End If
 End Sub
0
 
LVL 20

Expert Comment

by:ihenry
ID: 10869982
Or this article should be able to explain better,

Allowing Users to Select Items in a DataGrid Control
http://authors.aspalliance.com/aspxtreme/webforms/controls/allowinguserstoselectitemsindatagrid.aspx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now