Having a problem with my datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kimbred
    New Member
    • Jan 2009
    • 47

    Having a problem with my datagrid

    I select the delete button and it takes me to the event but I can't get the information about the row I'm deleting. It says the selected row is -1 when it's actually the third row. I have to pass the information to a structure befor the record can be deleted. How do I get this information?
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Could you please post the code that you have so far so that we can see what you're doing?

    Thanks,

    -Frinny

    Comment

    • kimbred
      New Member
      • Jan 2009
      • 47

      #3
      Don't really have much. My intentions are to take several values in the gridrow and pass them to a class that properly deletes the record. Below is all I have for the row deleted event.
      Code:
          protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
          {
      
              BLL_SelfService.DelPhnRec(Profile.Employees.EmpId,Convert.ToInt16(GridView1.SelectedRow.Cells[0]),Convert.ToInt16(GridView1.SelectedRow.Cells[1]),Convert.ToString(GridView1.SelectedRow.Cells[2]));
          }
      Last edited by Frinavale; Jan 23 '09, 08:59 PM. Reason: addded [code] tags

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Try implementing a method that handles the RowDeleting Event instead of the RowDeleted Event ;)

        -Frinny

        Comment

        • kimbred
          New Member
          • Jan 2009
          • 47

          #5
          This tells me that the selected row is NULL

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            You shouldn't be trying to get the Selected Row..

            You retrieve the row that the user wants to delete by getting the RowIndex from the "e" parameter (from the GridViewDeleteE ventArgs passed into the method).
            Code:
             Private Sub myGridView_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles myGridView.RowDeleting
                    Dim row = GV_Groups.Rows(e.RowIndex)
            End Sub
            Code:
            void myGridView_RowDeleting(Object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e ) 
            {
                   GridViewRow row = GV_Groups.Rows[e.RowIndex];
            }

            Comment

            • kimbred
              New Member
              • Jan 2009
              • 47

              #7
              Thanks for your help.

              Comment

              Working...