Solved

Capturing template button events in a datagrid???

Posted on 2004-04-20
3
945 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

631 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