473,394 Members | 1,715 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,394 software developers and data experts.

Buttons in a grid

Let's say I have a dataset with 1 table and it has 3 columns. One of the
columns is a primary key. The number of rows is unknown, but for
simplicity's sake let's say anywhere from 5 to 50 rows. I want to fill a
grid on screen and in each row add a new column and in that column put a
command button. I want every button to have the same event when clicked.
How do I do this so that when the button is clicked but in the click event I
at least get the primary key of the column in the row so that I can uniquely
identify that row?

Thank you.
Nov 18 '05 #1
3 989
Edward,

The datagrid comes with editing, updating, cancelling and deleting events
for just this purpose...

The basic principle is that a click then passes back the item (row) that was
clicked. From here you can examine any of the rows details (for id numbers
etc), and perform what ever action you want on that row... All this is done
around one event handler method.

Check out:
http://msdn.microsoft.com/library/de...tomcolumns.asp
http://aspnet.4guysfromrolla.com/articles/071002-1.aspx

Let me know if you need any help...

Dan.

"Edward W." <ed******@aol.comXSPAMMERIHATEYOU> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Let's say I have a dataset with 1 table and it has 3 columns. One of the
columns is a primary key. The number of rows is unknown, but for
simplicity's sake let's say anywhere from 5 to 50 rows. I want to fill a
grid on screen and in each row add a new column and in that column put a
command button. I want every button to have the same event when clicked.
How do I do this so that when the button is clicked but in the click event
I at least get the primary key of the column in the row so that I can
uniquely identify that row?

Thank you.

Nov 18 '05 #2
Edward, plenty of good articles like the ones Dan mentions. In the case where
the user won't see your key field (e.g. ID), you have a few options: a) use
datakeyfield, b) use a hidden column in the grid, or c) assign the ID to the
CommandArgument attribute of the button. I always use one of these methods so
I'm not forced to display the ID if I don't want to. It's also helpful in
cases where the ID you show is not the same ID you'd pass to a new page (e.g.
you might want to pass an encrypted version of the ID if the user is going to
see it in a query string, etc.).

"Edward W." wrote:
Let's say I have a dataset with 1 table and it has 3 columns. One of the
columns is a primary key. The number of rows is unknown, but for
simplicity's sake let's say anywhere from 5 to 50 rows. I want to fill a
grid on screen and in each row add a new column and in that column put a
command button. I want every button to have the same event when clicked.
How do I do this so that when the button is clicked but in the click event I
at least get the primary key of the column in the row so that I can uniquely
identify that row?

Thank you.

Nov 18 '05 #3
cast the sender object of the event handler to a datagridItem and then you
can access the rows and columns of the datagrid to determine the value

"Edward W." wrote:
Let's say I have a dataset with 1 table and it has 3 columns. One of the
columns is a primary key. The number of rows is unknown, but for
simplicity's sake let's say anywhere from 5 to 50 rows. I want to fill a
grid on screen and in each row add a new column and in that column put a
command button. I want every button to have the same event when clicked.
How do I do this so that when the button is clicked but in the click event I
at least get the primary key of the column in the row so that I can uniquely
identify that row?

Thank you.

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jon | last post by:
Hello, I have a datagrid and the data in it is dynamically created at runtime... For iCounter = 0 To dataset.Tables(0).Columns.Count - 1 Dim objbc As New BoundColumn() With objbc .DataField...
2
by: Will | last post by:
Hi I've been looking a way to put buttons in a column, but almost every example is for WebForms and I need it for WinForms... I found a way for doing it, with the DataGridColumnStyle class,...
2
by: Jorge Ayala | last post by:
Well I'm trying to catch and act upon a button event that is placed within the item template of a repeater control. Yet the code I'm using isn't working. What I've seen out there to explain how...
3
by: pmud | last post by:
Hi, I have an ASP.NET application using C# code. I am using a datagrid to display records from a database based on a user input, i.e a user enters a compnay name in text box & when he clicks a...
1
by: Matt | last post by:
Hi, I have a web form where a user can enter child parts for a given parent part. On the top of the page is a text box and a sumbit button labeled "Retrieve Child Parts". When type some part...
0
by: memanwar | last post by:
Throughout our system we use the DataGrid. One problem we've noticed is that the arrow buttons don't always work with our grids, clicking on them sometimes won't move the columns at all, or may...
5
by: acool | last post by:
I have been trying to do this for hours with only limited success. I have no idea why MS makes something that should be so straight forward a real pain. Can anyone point me in the right direction?
6
by: Totto | last post by:
Hi, Anyone know the best solution to dynamically add buttons to a asp 2.0 page using data from Sql server? Are there any contols suitable for this or is it best to iterate the dataset and...
3
by: skanemupp | last post by:
is there anyway to make this shorter? i hate having these big blocks of similar-looking code, very unaesthetic. maybe doesnt matter good-code-wise? anyway can i make some function that makes this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.