Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do not try to do both a click event handler and a command name, but instead just the command; like this:</p> <pre><code>&lt;ItemTemplate&gt; &lt;asp:ImageButton ID ="btnSave" runat="server" CommandName="SaveTitle" ImageUrl="~/images/download.jpg" CommandArgument='&lt;%# Container.DisplayIndex %&gt;' /&gt; &lt;/ItemTemplate&gt; </code></pre> <p>Also, make sure to set the <code>OnRowCommand</code> value in your grid view, like this:</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderColor="#336699" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" Font-Names="Verdana" Font-Size="10pt" OnRowCreated="GridView1_RowCreated" DataKeyNames="titleid" EnablePersistedSelection="True" EnableViewState="False" OnRowCommand="GridView1_RowCommand"&gt; </code></pre> <p>Finally, implement the <code>GridView1_RowCommand</code> method, like this:</p> <pre><code>protected void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) { // If multiple buttons are used in a GridView control, use the // CommandName property to determine which button was clicked. if(e.CommandName == "SaveTitle") { // Do logic here to save title } } </code></pre> <hr> <p>UPDATE:</p> <p>Instead of using the <code>Container.DisplayIndex</code> for the command argument, use the <code>TitleID</code> value of the binding source (LINQ query), like this:</p> <pre><code>&lt;ItemTemplate&gt; &lt;asp:ImageButton ID ="btnSave" runat="server" CommandName="SaveTitle" ImageUrl="~/images/download.jpg" CommandArgument='&lt;%# Eval("TitleID") %&gt;' /&gt; &lt;/ItemTemplate&gt; </code></pre>
    singulars
    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. This table or related slice is empty.
    1. 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