Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I worked it out based on JasonS response. What I did was create a hidden field in the Grid View like this:</p> <pre><code>&lt;asp:TemplateField ShowHeader="False"&gt; &lt;ItemTemplate&gt; &lt;asp:HiddenField ID="hdID" runat="server" Value='&lt;%# Eval("JobID") %&gt;' /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField Visible="False"&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID="lnkSelect" runat="server" CommandName="select" Text="Select" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; </code></pre> <p>Then on the OnRowDataBind have code to set the selected row</p> <pre><code>protected virtual void Grid_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // Click to highlight row Control lnkSelect = e.Row.FindControl("lnkSelect"); if (lnkSelect != null) { StringBuilder click = new StringBuilder(); click.AppendLine(m_View.Page.ClientScript.GetPostBackClientHyperlink(lnkSelect, String.Empty)); click.AppendLine(String.Format("onGridViewRowSelected('{0}')", e.Row.RowIndex)); e.Row.Attributes.Add("onclick", click.ToString()); } } } </code></pre> <p>And then in the Javascript I have code like this</p> <pre><code>&lt;script type="text/javascript"&gt; var selectedRowIndex = null; function onGridViewRowSelected(rowIndex) { selectedRowIndex = rowIndex; } function editItem() { if (selectedRowIndex == null) return; var gridView = document.getElementById('&lt;%= GridView1.ClientID %&gt;'); var cell = gridView.rows[parseInt(selectedRowIndex)+1].cells[0]; var hidID = cell.childNodes[0]; window.open('JobTypeEdit.aspx?id=' + hidID.value); } &lt;/script&gt; </code></pre> <p>Works a treat :-)</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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