Click here to Skip to main content
15,913,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a button in datagridview. After I click this button I need value of a column(number-column name) as I need to display details of that particular number.
Can any1 please help me out?

Thanking you in advance.
Posted

1 solution

in your row command event handler of the grid view, code something like this

VB
Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
 'create a variable to read the content of cell, the primary key of the record
       Dim myprimarykey As Integer
'read the value from the row(which is clicked) and cell (no) 
       myprimarykey=gridView1.Rows(e.CommandArgument).Cells.Item(0).Text
' write the code you want to be performed on it. e.g.
       MessageBox.Show("You pressed the button for the record" & myprimarykey)
end sub


you can also utilize e.CommandName (put the commandname in button description when designing gridview and adding a button column,) perform if-else to check which button was pressed (if the grid offers more than one type of button)

for more help, refer
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewcommandeventargs.aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900