1
  • I have a simple gridview.

  • 3 Columns |

    NAME AGE Birthday
    

On RowUpdated I want to get something like:

  Gridview1.Column[2].Cell[2].Text 

so I can get the value from the column 2. How can I do it?

Thank you. pS: row updated & row updating are the same thing?

asmgx
  • 7,328
  • 15
  • 82
  • 143
Inzi Irina
  • 267
  • 2
  • 5
  • 14
  • 2
    You know that [MSDN](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdating.aspx) is a good source for questions like _"row updated & row updating are the same thing?"_ ?! – Tim Schmelter Mar 15 '12 at 16:41
  • possible duplicate of http://stackoverflow.com/questions/9687589/how-to-check-if-value-from-a-cell-in-a-column-is-null – Pankaj Mar 15 '12 at 16:42

3 Answers3

7

Here's the MSDN article with example code: GridView.RowUpdating Event

Row updated and updating are not the same. Updating happens before the GridView control updates the row and updated is after the data has been updated.

In your Gridview control you need to add OnRowUpdating="TaskGridView_RowUpdating"

Assuming the value is in a textbox in the Age column this is how you would store the value in a string:

protected void TaskGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {    
    GridViewRow row = TaskGridView.Rows[e.RowIndex];
    String str = ((TextBox)(row.Cells[1].Controls[0])).Text;
  }
zeroef
  • 1,949
  • 23
  • 32
  • this is it right ? dt.Rows[row.DataItemIndex]["Id"] = ((TextBox)(row.Cells[1].Controls[0])).Text; – Inzi Irina Mar 15 '12 at 16:43
  • @InziIrina - The example takes the value of the textbox control and adds it to a datatable. – zeroef Mar 15 '12 at 16:53
  • tried for so many days and still couldn't find a way, I've tried all examples I found and I couldn't find a way to get on update the value of a cell from. – Inzi Irina Mar 15 '12 at 16:55
  • @InziIrina - Every time I shake my magic 8 ball it keeps responding with "Outlook not so good" – zeroef Mar 15 '12 at 17:54
1

If you have data directly in the GridView cell (no label or textbox, etc) then this worked for me

protected void GridView1_RowUpdating(object sender,    
System.Web.UI.WebControls.GridViewUpdateEventArgs e )
   {
   int row;
   int colidx =1;
   string cellvalue;

   GridViewRow row = Gridview1.rows[e.rowindex]
   cellvalue = row.cells[colidx].text;
   }
derek
  • 11
  • 1
0

Try this:

Gridview1.Rows[Gridview1.EditIndex].Cells[2].Text.ToString();
Kash
  • 8,799
  • 4
  • 29
  • 48