Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing column value from specific row index of a GridView
    primarykey
    data
    text
    <p>Suppose I have a gridview containing some bound fields and a template field. The template field contains a button (btnUpload).</p> <p>btnUpload triggers a modalpopupextender to display a panel which contains some controls and a submit button.</p> <p>What I need to be able to do is to get the value from cell 0 of the row btnUpload was clicked on and pass it to the panel so I can retrieve some data into the panel's controls in the panel_load event based on that value from cell 0 of the gridview.</p> <p>I thought I could do this by storing the value from cell 0 in a session variable but not sure if this is the 'best' way of doing this?</p> <p><strong>UPDATE - Using hidden fields on the panel to store row index as suggested by Karl</strong></p> <p>I have added two hidden fields to the panel and I populate them as below:</p> <pre><code>If e.CommandName = "Upload" Then Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow) Dim ref As String = CType(row.Cells(0), DataControlFieldCell).Text Dim dt As String = CType(row.Cells(2), DataControlFieldCell).Text hfRef.Value = ref hfDate.Value = dt End If </code></pre> <p>This is working and populating the hidden fields OK. However in the btnSubmit_Click event procedure on the panel I am doing the following the variables I am assigning are not getting a value from the hidden fields:</p> <pre><code>If fuCertificate.HasFile Then Dim fileName As String = Path.GetFileName(fuCertificate.PostedFile.FileName) fuCertificate.SaveAs(Server.MapPath("~/CalibrationCerts/" &amp; fileName)) Dim ref As String = hfRef.Value Dim dt As String = hfDate.Value Dim dc As New ExternalCalibrationDataContext Dim thisRecord = (From x In dc.ext_calibration_records Where x.calibration_no = ref AndAlso x.calibration_date = dt).ToList()(0) thisRecord.certificate_no = txtCertNumber.Text thisRecord.certificate = "~/CalibrationCerts/" &amp; fileName Else lblError.Text = "Please select a file to upload" End If </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload