The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Adding Image Buttons to a DataGrid

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic    
Flat View: This topic has 0 replies on 1 page
Doug Thews

Posts: 866
Nickname: dougthews
Registered: Jul, 2003

Doug Thews is a software developer/manager for D&D Consulting Services with 18+ years of experience
Adding Image Buttons to a DataGrid Posted: Jul 10, 2003 1:12 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Doug Thews.
Original Post: Adding Image Buttons to a DataGrid
Feed Title: IlluminatiLand
Feed URL: http://apps5.oingo.com/apps/domainpark/domainpark.cgi?client=netw8744&s=JETBRAINS.COM
Feed Description: A technology blog for people enlightened enough to think for themselves
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Doug Thews
Latest Posts From IlluminatiLand

Advertisement

I've seen a few posts recently about how to put actionable image buttons in a column for a datagrid, so I thought I'd show an example.

The first thing to do is to add a ButtonColumn inside your DataGrid. This is a sample for a Delete button image (I use a 1% width to match the size of my image):






Assuming our DataGrid is named DataGrid1, you'll want to handle the DataGrid1.ItemCommand event. The event passes back the command name (remember DeleteRecord from our command button definition?) as the type DataGridCommandEventArgs. Here's a sample for interacting with our DeleteRecord command:

Protected Sub DataGrid1_ItemCommand(ByVal sender As System.Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
Handles DataGrid1.ItemCommand


' Check to see if the user selected the pager. If not, then this must be
' a command button
If (e.Item.ItemType <> ListItemType.Pager) Then

Select Case e.CommandName
 Case "DeleteRecord"
  ' Do your thing here

End Select
Else
 ' This section would be where any page control stuff goes
End If
End Sub

You'll notice that we also checked to make sure that the command type was not a pager before we went off and checked command name (which would have been null in that case).

That's pretty much it. I use this in my sample HomeInventory system that I use to proof out a lot of ASP.NET tools & techniques. Check it out and let me know what you think.

Read: Adding Image Buttons to a DataGrid

Topic: Rockets on Prisoner Award Previous Topic    

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use