0

How can I get the value from data table of the gridview for a specific column where the control is a dropdownlist.So I don't want to get the dropdownlist value I want to get the value for the column that is set in the datatable.

I need it in row updating event

TOP KEK
  • 2,593
  • 5
  • 36
  • 62
Alexander
  • 187
  • 2
  • 5
  • 15
  • What have you tried so far? Can you include some code? It's very difficult to assess the question as is. – KP. Apr 25 '12 at 12:58

1 Answers1

0

The value in the dbms can only be different if the user has changed it, so either select it from dbms again or - better - use the OldValues Dictionary from GridViewUpdateEventArgs.

void GridView_RowUpdating(Object sender, GridViewUpdateEventArgs e)
{
    String fieldName = "FooColumn";
    Object oldValue = e.OldValues[fieldName];
}

The OldValues property is automatically populated with the original values of all the field name/value pairs in the row. A separate entry is added to the OldValues property for each field in the row.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Object reference not set to an instance of an object. – Alexander Apr 25 '12 at 13:06
  • @Alexander: That's the message of a famous exception type. What is `null`, have you changed `FooColumn` to the correct field name? – Tim Schmelter Apr 25 '12 at 13:08
  • ofc I've changed , I've tried Label2.Text = oldValue.ToString(); to check if I can get it..and it didn't worked. The colum value is not null – Alexander Apr 25 '12 at 13:10
  • @Alexander: Use the debugger. Set a breakpoint at this line and inspect the values of e.OldValues in the quick-watch window. The Dictionary is populated only with declarative datasource controls like ObjectDataSource and **SqlDataSource**, hence it should work for you. – Tim Schmelter Apr 25 '12 at 13:25