Click here to Skip to main content
13,094,001 members (59,463 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all!
i have a problem is.. i dont know handles event when i clicking on button in datagridview, i design my form like below picture[^]

i want when i clicked on the button then it show the infor of that row. Please reply me soon or mail me with Email: [removed]
Posted 7-Mar-12 20:55pm
Updated 7-Mar-12 20:56pm
walterhevedeich 8-Mar-12 2:57am
I've removed your email address. If someone knows the answer, they will be posting it here, not on your email.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Please, look at your screen.

Why the heck do you want a button on each and every row which does exactly the same thing, but for a different row of data?
All the buttons are doing is wasting screen real-estate and making it look clumsy.

Why not just show the data for the currently selected row? That way the user doesn't have to click on a button at all - when the selected row changes, the information is automatically updated.
Or, if you are bringing up a dialog to show the data, consider a single button which shows the data for the selected row? Again, it reduces the screen footprint, and looks less "busy". It's also pretty simple for the user to work out - the button is always in the same place, rather than moving with the row.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you are using the TemplateField object and have to access the row index in the event handler method, set the button's CommandArgument property to an expression that identifies the current row. Sample code is:

    <asp:Button ID="AddButton" runat="server"
      CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
      Text="Add to Cart" />

Create a method for the RowCommand event of the GridView control as:
protected void GridView1_RowCommand(object sender,
  GridViewCommandEventArgs e)
  if (e.CommandName == "AddToData")
    // Add code here to related to the row.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Ok i using not c# :d i testing hanldes event on datagridview :d
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

i have just complete :d it run ok. this is my code.

Private Sub gvView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gvView.CellContentClick
        Dim strID As String
        Dim strName As String
        Dim strPricw As String
        Dim strQuan As String
        If e.ColumnIndex = 0 Then
            strID = gvView.Rows(e.RowIndex).Cells(3).Value.ToString()
            strName = gvView.Rows(e.RowIndex).Cells(4).Value.ToString()
            strPricw = gvView.Rows(e.RowIndex).Cells(5).Value.ToString()
            strQuan = gvView.Rows(e.RowIndex).Cells(6).Value.ToString()
            MessageBox.Show("You has choosen: " & strID & " | " & strName & " | " & strPricw & " | " & strQuan)
        End If
    End Sub

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 8 Mar 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100