title: Sending row value to another page using gridview row double click
body: <p>I have a gridview which i bind my system's Demands table(table name like DemandFiche). At the same time,there is a fiche record details table which i keep my fiche records details (table name like DemandFicheDetails) (Also i keep my DemandFiche table "ID"s in DemandFicheDetails table as "DemandFicheID".So there is a connection between these two tables)</p>
  
  <p>I want to double click on selected row and pass ID value for seeing selected record's details to another page (DemandsDetailForm).</p>
  
  <p>Btw,I use asp.net 4.5 and entity framework.</p>
  
  <p>How can i do that? Thanks.</p>
  
  <p>Here is aspx code (DemandsForm.aspx) : </p>
  
  <pre><code>        &lt;div&gt;
      &lt;asp:GridView runat="server" OnSelectedIndexChanged="DemandsGridView_SelectedIndexChanged"  OnRowDataBound="DemandsGridView_RowDataBound" Width="1300px" AllowPaging="True" AllowSorting="True" ID="GridView1" DataSourceID="DemandsEntityDataSource" AutoGenerateColumns="False"&gt;
          &lt;AlternatingRowStyle BackColor="#CCCCCC" /&gt;
          &lt;SelectedRowStyle BackColor="Yellow" /&gt;
          &lt;Columns&gt;
              &lt;asp:BoundField DataField="ID" Visible="False" /&gt;
              &lt;asp:BoundField DataField="DATE_" HeaderText="Date" Visible="True" DataFormatString="{0:dd/MM/yyyy}" /&gt;
              &lt;asp:BoundField DataField="FICHENO" HeaderText="Fiche No" Visible="True" /&gt;
              &lt;asp:BoundField DataField="DOCODE" HeaderText="Docode" Visible="True" /&gt;
              &lt;asp:BoundField DataField="STATUS" HeaderText="Status" Visible="True" /&gt;
              &lt;asp:BoundField DataField="BRANCH" HeaderText="Branch" Visible="True" /&gt;
              &lt;asp:BoundField DataField="DEPARTMENT" HeaderText="Department" Visible="True" /&gt;
              &lt;asp:BoundField DataField="SOURCEINDEX" HeaderText="Sourceindex" Visible="True" /&gt;
              &lt;asp:BoundField DataField="FACTORY" HeaderText="Factory" Visible="True" /&gt;
          &lt;/Columns&gt;
          &lt;EditRowStyle ForeColor="#CC3300" /&gt;
      &lt;/asp:GridView&gt;
      &lt;asp:EntityDataSource ID="DemandsEntityDataSource" runat="server" ConnectionString="name=PmsEntities" DefaultContainerName="PmsEntities" EntitySetName="PMS_DEMANDSVIEW" EntityTypeFilter="PMS_DEMANDSVIEW"&gt;
      &lt;/asp:EntityDataSource&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And here is code behind : </p>
  
  <pre><code>    public partial class DemandsForm : System.Web.UI.Page
  {
      public DemandsDetailForm DemandsDetailForm;
      private PmsEntities dbContext;
  
      protected void Page_Load(object sender, EventArgs e)
      {
          dbContext = new PmsEntities();
      }
  
      protected void DemandsGridView_SelectedIndexChanged(object sender, EventArgs e)
      {
  
      }
  
      protected void DemandsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              e.Row.Attributes.Add("OnMouseOver", "this.style.cursor = 'hand';");
  
              var selectButton = new LinkButton()
              {
                  CommandName = "Select",
                  Text = e.Row.Cells[0].Text
              };
  
              selectButton.Font.Underline = false;
              selectButton.ForeColor = Color.Black;
  
              e.Row.Cells[0].Controls.Add(selectButton);
              //e.Row.Attributes["OnClick"] = Page.ClientScript.GetPostBackClientHyperlink(selectButton, "");
              e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(DemandsGridView, "Select$" + e.Row.RowIndex);
  
              e.Row.Attributes.Add("ondblclick", "__doPostBack('DemandsGridView','Select$" + e.Row.Cells[0] + "');");
          }
      }
  }
  </code></pre>