Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Capturing template button events in a datagrid???

Posted on 2004-04-20
3
Medium Priority
?
948 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 375 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

876 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