title: How to get and pass value from GridView to Method being called by DropDownList in GridView?
body: <p>I have the following <code>GridView</code> containing a <code>DropDownList</code> which calls a method based on <code>SelectedValue</code>:</p>
  
  <p>On the row where the selection is being made, how do I get the <code>Customer ID</code> from the <code>GridView</code> and pass it as an argument to the Method being called below? </p>
  
  <p><em>Code:</em></p>
  
  <pre><code>&lt;asp:GridView ID="grdLoadData" AutoGenerateColumns="false" runat="server"&gt;
  
  &lt;Columns&gt;
  &lt;asp:TemplateField HeaderText="Example"&gt;
  &lt;ItemTemplate&gt;
  &lt;asp:DropDownList ID="ddlExampleDropDownList"  runat="server" 
       AutoPostBack="true" Width="100" 
      OnSelectedIndexChanged="ddlExampleDropDownList_SelectedIndexChanged"&gt;
      &lt;asp:ListItem Text="---- Select --" Value="select" /&gt;
      &lt;asp:ListItem Text="Do Task A" Value="Task A" /&gt;
      &lt;asp:ListItem Text="Do Task B" Value="Task B" /&gt;
  &lt;/asp:DropDownList&gt; 
  &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  
  &lt;asp:BoundField DataField="LAST_NAME" HeaderText="Last Name" /&gt;
  &lt;asp:BoundField DataField="FIRST_NAME" HeaderText="First Name" /&gt;
  &lt;asp:BoundField DataField="MiDDLE_NAME" HeaderText="Middle Name" /&gt;
  
  &lt;asp:TemplateField HeaderText="Customer ID"&gt;
  &lt;ItemTemplate&gt;
  &lt;asp:Label ID="lblCustomerID" Text='&lt;%#Eval("CUST_ID") %&gt;' runat="server" /&gt;
  &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  
  &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Code Behind:</p>
  
  <pre><code>    public string DoTaskA(string customerId)
      {
          return customerId;
      }
  
      public string DoTaskB(string customerId)
      {
          return customerId;
      }
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              LoadData();
          }  
      }
  
      protected void ddlExampleDropDownList_SelectedIndexChanged(object sender, EventArgs e)
      {
          DropDownList dropDownList = (DropDownList)sender;
          GridViewRow gridViewRow = (GridViewRow)dropDownList.Parent.Parent;
  
           if(dropDownList.SelectedValue=="Task A")
           {
               //Pass Customer ID here
               DoTaskA();
           }
           else if(dropDownList.SelectedValue=="Task B")
           {
               //Pass Customer ID here
               DoTaskB();
           }
      }
  </code></pre>