Solved

Capturing template button events in a datagrid???

Posted on 2004-04-20
3
940 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

11 Experts available now in Live!

Get 1:1 Help Now