Get the cell value of a GridView row

Lily

I am using the GridView - AutoGenerateSelectButton = "True" to select the row in order to get the Column 1 cell value.

I have tried:

GridViewRow row = dgCustomer.SelectedRow;
TextBox1.Text = "Cell Value" + row.Cells[1].Text + "";

And it writes the "Cell Value" but nothing else.

I finally was able to get the number of the row (index) but not the cell value.

GridViewRow row = dgCustomer.SelectedRow;
TextBox1.Text = row.RowIndex.ToString();

I have tried:

TextBox1.Text = dgCustomer.Rows[row.RowIndex].Cells[1].Text;

and still returns the index row.

Any other suggestions? Thank you!

Dennis R

Try changing your code to

// Get the currently selected row using the SelectedRow property.
GridViewRow row = dgCustomer.SelectedRow;

// And you respective cell's value
TextBox1.Text = row.Cells[1].Text

UPDATE: (based on my comment) If all what you are trying to get is the primary key value for the selected row then an alternate approach is to set

datakeynames="yourprimarykey"

for the gridview definition which can be accessed from the code behind like below.

TextBox1.Text = CustomersGridView.SelectedValue.ToString();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get value of databound cell in GridView

From Dev

How to get a cell value or row value in ControlGrid Level 1 GridView C# - DevExpress

From Dev

Get footer row cell values of gridview

From Dev

Get footer row cell values of gridview

From Dev

Needing row&col indices in code behind to get selected gridview cell value

From Dev

How to get value of a gridview cell in this scenario

From Dev

How to get cell value in GridView (WITHOUT using cell index)

From Dev

Get value of a specific item in a row of Gridview with Javascript

From Dev

asp.net gridview if cell row value is equal then

From Dev

C# Getting cell value on button click for each row on gridview

From Dev

Gridview: Change link button text base on value of cell in same row

From Dev

Get a cell value from a row based on another cell value

From Dev

JQuery get cell value from row object

From Dev

get value of the cell in the last table row

From Dev

Get value of a table cell in another row

From Dev

get the value of first cell of last row

From Dev

Get cell value from a pandas DataFrame row

From Dev

Get an entire row based on value of cell in excel

From Dev

Get first cell value of each row in table

From Dev

How to get the value of a cell specifies the GridView ASP.NET

From Dev

Cell on last row of GridView will not color in

From Dev

move Rows up and down or change row color if the row cell value are the same gridview devexpress winforms c#?

From Dev

How to get the value of formatted cell value of a row in jqgrid

From Dev

How to get field value of selected Row Devexpress GridView?

From Dev

Get value of gridview.selected.row[] with visible property = 'false'

From Dev

How to Get Value from GridView (row click) in javascript

From Dev

How to get gridview row value in string without using rowindex?

From Dev

how to get the specific row value from corresponding button click in gridview

From Dev

Get Clicked Row of GridView

Related Related

  1. 1

    Get value of databound cell in GridView

  2. 2

    How to get a cell value or row value in ControlGrid Level 1 GridView C# - DevExpress

  3. 3

    Get footer row cell values of gridview

  4. 4

    Get footer row cell values of gridview

  5. 5

    Needing row&col indices in code behind to get selected gridview cell value

  6. 6

    How to get value of a gridview cell in this scenario

  7. 7

    How to get cell value in GridView (WITHOUT using cell index)

  8. 8

    Get value of a specific item in a row of Gridview with Javascript

  9. 9

    asp.net gridview if cell row value is equal then

  10. 10

    C# Getting cell value on button click for each row on gridview

  11. 11

    Gridview: Change link button text base on value of cell in same row

  12. 12

    Get a cell value from a row based on another cell value

  13. 13

    JQuery get cell value from row object

  14. 14

    get value of the cell in the last table row

  15. 15

    Get value of a table cell in another row

  16. 16

    get the value of first cell of last row

  17. 17

    Get cell value from a pandas DataFrame row

  18. 18

    Get an entire row based on value of cell in excel

  19. 19

    Get first cell value of each row in table

  20. 20

    How to get the value of a cell specifies the GridView ASP.NET

  21. 21

    Cell on last row of GridView will not color in

  22. 22

    move Rows up and down or change row color if the row cell value are the same gridview devexpress winforms c#?

  23. 23

    How to get the value of formatted cell value of a row in jqgrid

  24. 24

    How to get field value of selected Row Devexpress GridView?

  25. 25

    Get value of gridview.selected.row[] with visible property = 'false'

  26. 26

    How to Get Value from GridView (row click) in javascript

  27. 27

    How to get gridview row value in string without using rowindex?

  28. 28

    how to get the specific row value from corresponding button click in gridview

  29. 29

    Get Clicked Row of GridView

HotTag

Archive