Can't get the values of the cells in my grid view

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

    Can't get the values of the cells in my grid view

    Can someone help me? Using the following code, I should get the values in the cells of the selected row of my gridview. When I get the value of the cells, their empty.

    Code:
     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
    
            GridViewRow  row = GridView1.Rows[e.RowIndex];
            BLL_SelfService.DelPhnRec(Profile.Employees.EmpId, Convert.ToInt16(row.Cells[0]), Convert.ToInt16(row.Cells[1]), Convert.ToString(row.Cells[2]));
        }
    Last edited by Frinavale; Jan 26 '09, 05:23 PM. Reason: added [code] tags
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    In your PageLoad event, are you doing a DataBind on your GridView?
    When you do this, any values entered while the user was editing the row will be reset because the GridView's data source has been reset.

    -Frinny

    Comment

    • kimbred
      New Member
      • Jan 2009
      • 47

      #3
      Not Binding on the Page Load.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Oh, I see what you're doing.
        You have to know what type of control is being used to display the data in the cell, then you need to retrieve the text being displayed in that control.


        For Example:
        Code:
        //note: here I know that the first cell contains a Label that is used to display the content
        String someText = (Label) row.Cells[0].Controls[0].Text; 
        int someNumber =  Convert.ToInt16(someText);

        Comment

        Working...