Getting the value of a column of selected row in DataGridView
-
Hi, I have problem in retrieving the value of a column of selected row in DataGridView control using c#.net 2005
VijayaRam
easy one
public String returnGridViewCellValue(GridViewRow row, String fieldName) { String result = String.Empty; try { result = DataBinder.Eval(row.DataItem, fieldName).ToString(); } catch { result = String.Empty; // or result = fieldName + " not found"; } return result; }
-
Hi, I have problem in retrieving the value of a column of selected row in DataGridView control using c#.net 2005
VijayaRam
Here is an example(getting the value of a cell of the first row selected ):
DatagridView oGrid; //If you know the ordinal of the column if( oGrid.SelectedRows.Count>0 ) { object oValue = oGrid.SelectedRows[0].Cells[0].Value; } //If you know the name of the column if( oGrid.SelectedRows.Count>0 ) { object oValue = oGrid.SelectedRows[0].Cells["colName"].Value; } //Then you can try to Convert the object to a different type.
Visit my blog at http://dotnetforeveryone.blogspot.com/