Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have you set the GridView's <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeynames.aspx" rel="nofollow noreferrer">DataKeyNames property</a>? It needs to be set to the item's primary key to uniquely identify the record to modify. If you didn't set it, clicking Delete (or Edit) would cause a postback that doesn't affect anything since a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datakey.aspx" rel="nofollow noreferrer">DataKey</a> wasn't associated with each GridView row.</p> <p>According to the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeys.aspx" rel="nofollow noreferrer">GridView.DataKeys property</a> page:</p> <blockquote> <p>When the DataKeyNames property is set, the GridView control automatically creates a DataKey object for each row in the control. The DataKey object contains the values of the field or fields specified in the DataKeyNames property.</p> </blockquote> <p>For example, let's say you're deleting a product item that's identified by a ProductID field.</p> <p>Your SqlDataSource might look something like this:</p> <pre><code>&lt;asp:SqlDataSource ID="ProductsDataSource" runat="server" ConnectionString="&lt;%$ ConnectionStrings:NORTHWNDConnectionString %&gt;" SelectCommand= "SELECT [ProductID], [ProductName], [UnitPrice] FROM [Products]" DeleteCommand="DELETE FROM Products WHERE ProductID = @ProductID"&gt; &lt;DeleteParameters&gt; &lt;asp:Parameter Name="ProductID" /&gt; &lt;/DeleteParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre> <p>You would then assign the same "ProductID" primary key to the GridView's DataKeyNames property:</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="ProductID" ... </code></pre> <p>These tutorials may be helpful to you:</p> <ul> <li><a href="http://www.asp.net/Learn/Data-Access/tutorial-49-cs.aspx" rel="nofollow noreferrer">Inserting, Updating, and Deleting Data with the SqlDataSource</a></li> <li><a href="http://www.asp.net/Learn/Data-Access/tutorial-16-cs.aspx" rel="nofollow noreferrer">An Overview of Inserting, Updating, and Deleting Data</a></li> </ul>
 

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