Get the cell value of a GridView row

后端 未结 8 1080
灰色年华
灰色年华 2021-01-01 18:23

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

I have tried:

         


        
8条回答
  •  鱼传尺愫
    2021-01-01 18:49

    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();
    

提交回复
热议问题