473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ASP.NET C# Datagrid button column event

chathura86
227 100+
I have a datagrid and I used a template column with an asp:button on it and I want to respond to a button click and find which row was selected. How would I do this?

Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateColumn HeaderText=" " ItemStyle-HorizontalAlign="Center">
  2.     <ItemTemplate>
  3.         <asp:Button ID="btnAddToCart" Text="Add to cart" runat="server" />
  4.     </ItemTemplate>
  5. </asp:TemplateColumn>
  6.  
Thank you,
Chathura Bamunusinghe.
Sep 8 '08 #1
2 3532
nateraaaa
663 Expert 512MB
<asp:TemplateColumn HeaderText=" " ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="btnAddToCart" Text="Add to cart" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
Add a CommandArgument and a CommandName to your button. Then in the ItemCommand event of your datagrid check for the value of e.CommandName.
Expand|Select|Wrap|Line Numbers
  1. if(e.Item.ItemType != ListItemType.Header && e.Item.Type != ListItemType.Pager)
  2. {
  3. if(e.CommandName == "YourCommandName")
  4. {
  5. //do something here. You can use the e.CommandArgument value. I usually set this value to the DB identity column so I can access a specific row in the DB to delete or update 
  6. }
  7. }
Nathan
Sep 8 '08 #2
chathura86
227 100+
it works

thanks a lot for the help

regards,
chathura bamunusinghe
Sep 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Griff | last post by:
Hi, I have a button column placed on a datagrid at design time that is captioned "Delete". When the user clicks the button, I want to display a confirmation message, that they want to delete...
2
by: Raj | last post by:
Hi, When we are sorting the DataGrid Boolean column the grid is becoming redcross. I have my own PPMIPDataGridBoolColumn class inherited from System.Windows.Forms.DataGridBoolColumn. In this...
1
by: Javier Ros | last post by:
hi guys, I´m working with datagrids and use the button columns, but I don´t like the buttons prefers the imagebutton, how to put a image in the place of button? without change the HTML code,...
1
by: Manu | last post by:
Is it possible to make a button on a DataGrid template column, Trigger the DataGrid "Selected Index change" event. Is it possible to trigger that event not through the button column ?
3
by: JL | last post by:
Hi all, I created a datagrid for information display, the layout as following, Button column:sales_no Datatextfield: sales_no CommandName: sales_no How can i get the clicked cell of...
2
by: Patrick Delifer | last post by:
Hi, I am trying to implement a JS confirm dialog when a user is deleting something off my Datagrid. The problem is that I don't have a Delete button in which case I could write the following...
1
by: MattB | last post by:
I have a button column in a datagrid that is the delete button. Right now it is just a text link. When I go into the Property Builder My button choices are only LinkButton or PushButton. I'd like...
1
by: Patrick B. | last post by:
is it possible to create a column in a datagrid control that has button controls embedded in each of the cells of the column?
0
by: herman404 | last post by:
Hi everyone, I'm trying to dynamically add 3 button columns to a DataGrid object that I have on an ASP.net webpage, but I don't see any documentation on how to do it. I've seen plenty of examples...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.