title: SQLDataSource DeleteCommand to get parameters
body: <p>I am having some problems passing parameters to a DELETE command, and cant seem to get a good understanding on how it works.</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="sdsPropertyList"
      runat="server"
      ProviderName="&lt;%$ appSettings:ProviderName %&gt;"
      ConnectionString="&lt;%$ appSettings:ConnectionString %&gt;"
      SelectCommand="selPropertyByAcntID"
      SelectCommandType="StoredProcedure"
      OnSelecting="sdsPropertyList_Selecting"
      OnSelected="sdsPropertyList_Selected" 
      DeleteCommand="delPropertyByPropID" 
      DeleteCommandType="StoredProcedure"
      OnDeleting="sdsPropertyList_Deleting"
      OnDeleted="sdsPropertyList_Deleted"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:Parameter Name="in_acntID" Type="Int32" DefaultValue="0" /&gt;
      &lt;/SelectParameters&gt;
      &lt;DeleteParameters&gt;
          &lt;asp:Parameter Name="in_acntID" Type="Int32" DefaultValue="0" /&gt;
          &lt;asp:Parameter Name="in_propID" Type="Int32" DefaultValue="0" /&gt;
      &lt;/DeleteParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  
  &lt;asp:GridView ID="gvProperty" runat="server" DataSourceID="sdsPropertyList" 
      AutoGenerateColumns="false" CssClass="gvPropList"&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField HeaderText="ID" InsertVisible="true" DataField="prop_id" ReadOnly="true" Visible="False" /&gt;
          &lt;asp:BoundField HeaderText="Property" DataField="prop_title" 
              ItemStyle-CssClass="gvPropTitle" &gt;
          &lt;ItemStyle CssClass="gvPropTitle" /&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:BoundField HeaderText="Units" DataField="unitCount" 
              ItemStyle-CssClass="gvUnitCount" &gt;
          &lt;ItemStyle CssClass="gvUnitCount" /&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:BoundField DataField="prop_lastmodified" HeaderText="Last Modified" 
              ItemStyle-CssClass="gvDate" DataFormatString="{0:M/dd/yyyy hh:mm tt}" &gt;
          &lt;ItemStyle CssClass="gvDate" /&gt;
          &lt;/asp:BoundField&gt;
          &lt;asp:TemplateField&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:LinkButton ID="lbtnEdit" runat="server" CommandName="EditRecord" Text="Edit" CommandArgument='&lt;%# Eval("prop_id") %&gt;'&gt;&lt;/asp:LinkButton&gt;
                  &lt;asp:LinkButton ID="lbtnDelete" runat="server" CommandName="Delete" Text="Delete" CommandArgument='&lt;%# Eval("prop_id") %&gt;'&gt;&lt;/asp:LinkButton&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:LinkButton ID="lbtnAdd" runat="server" CommandName="AddRecord" Text="Add" CommandArgument='&lt;%# Eval("prop_id") %&gt;'&gt;&lt;/asp:LinkButton&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
      &lt;HeaderStyle CssClass="headerPropList"/&gt;
      &lt;RowStyle CssClass="gvPropRow" /&gt;
  &lt;/asp:GridView&gt;
  
  protected void sdsPropertyList_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
      {
          int userID = Convert.ToInt32(Page.User.Identity.Name);
          if (userID != 0)
              e.Command.Parameters["in_acntID"].Value = userID;
      }
  
  protected void sdsPropertyList_Deleting(object sender, SqlDataSourceCommandEventArgs e)
      {
          int userID = Convert.ToInt32(Page.User.Identity.Name);
          if (userID != 0)
          {
              e.Command.Parameters["in_acntID"].Value = userID;
          }
      }
  </code></pre>
  
  <p>The SELECT statement is straightforward which requires one input parameter of userID. 
  However, the DELETE statement, requires 2 parameter inputs. 
  in_acntID = userID
  in_propID = the boundfield datafield prop_id </p>
  
  <p>What am I doing wrong? and should the CommandName and CommandArgument be passed at the ItemTemplate level if I have it defined at the SqlDataSource level?</p>
  
  <p>I want the delete button to achieve the following:</p>
  
  <ol>
  <li>delete records from table(s) in DB</li>
  <li>remove the row from the gridview </li>
  </ol>
  
  <p>UPDATE</p>
  
  <p>After some additional research, I've found that, the NAME for parameters and HeaderText for Boundfield must be the same so that the values within your gridview can be used by the SQL commands of the datasource.</p>
  
  <p>With the exception of the initial select commant, i have removed all the code behind references.</p>
  
  <p>All is working corrently now.</p>