Connecting Tech Pros Worldwide Help | Site Map

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

Member
 
Join Date: Jan 2009
Posts: 47
#1: Jan 26 '09
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.

Expand|Select|Wrap|Line Numbers
  1.  protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  2.     {
  3.  
  4.         GridViewRow  row = GridView1.Rows[e.RowIndex];
  5.         BLL_SelfService.DelPhnRec(Profile.Employees.EmpId, Convert.ToInt16(row.Cells[0]), Convert.ToInt16(row.Cells[1]), Convert.ToString(row.Cells[2]));
  6.     }
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: Jan 26 '09

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


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
Member
 
Join Date: Jan 2009
Posts: 47
#3: Jan 26 '09

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


Not Binding on the Page Load.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#4: Jan 26 '09

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


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:
Expand|Select|Wrap|Line Numbers
  1. //note: here I know that the first cell contains a Label that is used to display the content
  2. String someText = (Label) row.Cells[0].Controls[0].Text; 
  3. int someNumber =  Convert.ToInt16(someText);
Reply