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!
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With