Connecting Tech Pros Worldwide Help | Site Map

Having a problem with my datagrid

Member
 
Join Date: Jan 2009
Posts: 47
#1: Jan 23 '09
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's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: Jan 23 '09

re: Having a problem with my datagrid


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

Thanks,

-Frinny
Member
 
Join Date: Jan 2009
Posts: 47
#3: Jan 23 '09

re: Having a problem with my datagrid


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.
Expand|Select|Wrap|Line Numbers
  1.     protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
  2.     {
  3.  
  4.         BLL_SelfService.DelPhnRec(Profile.Employees.EmpId,Convert.ToInt16(GridView1.SelectedRow.Cells[0]),Convert.ToInt16(GridView1.SelectedRow.Cells[1]),Convert.ToString(GridView1.SelectedRow.Cells[2]));
  5.     }
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#4: Jan 23 '09

re: Having a problem with my datagrid


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

-Frinny
Member
 
Join Date: Jan 2009
Posts: 47
#5: Jan 23 '09

re: Having a problem with my datagrid


This tells me that the selected row is NULL
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#6: Jan 26 '09

re: Having a problem with my datagrid


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 GridViewDeleteEventArgs passed into the method).
Expand|Select|Wrap|Line Numbers
  1.  Private Sub myGridView_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles myGridView.RowDeleting
  2.         Dim row = GV_Groups.Rows(e.RowIndex)
  3. End Sub
Expand|Select|Wrap|Line Numbers
  1. void myGridView_RowDeleting(Object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e ) 
  2. {
  3.        GridViewRow row = GV_Groups.Rows[e.RowIndex];
  4. }
Member
 
Join Date: Jan 2009
Posts: 47
#7: Jan 26 '09

re: Having a problem with my datagrid


Thanks for your help.
Reply