Note that there are some explanatory texts on larger screens.

plurals
  1. POIn a GridView, how to add multiple commands to one item template?
    text
    copied!<p>I stripped this example to make it simple. I have a gridview with a template field. The template field contains two buttons and a label (They must be in the same template field). I want the first button to set the label text to "Win", and the other button to set the label text to "fail". The onrowcommand doesnt seem to be triggered by buttons in a template field. How can I accomplish this? </p> <p>My gridview code is below:</p> <pre><code> &lt;asp:GridView ID="GridView1" runat="server" EnableModelValidation="True" AutoGenerateColumns="False" OnRowCommand="Gridview1_RowCommand"&gt; &lt;Columns&gt; &lt;asp:TemplateField ShowHeader="False"&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID="btnWin" runat="server" CommandName="Win" Text="Win" /&gt; &lt;asp:Button ID="btnFail" runat="server" CommandName="Fail" Text="Fail" /&gt; &lt;asp:Label ID="lblStatus" runat="server" Text='&lt;%# Bind("text") %&gt;'&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>and my code behind:</p> <pre><code> protected void Page_Load(object sender, EventArgs e) { DataTable myTable = new DataTable(); myTable.Columns.Add("text", typeof(string)); myTable.Rows.Add("First Entry"); myTable.Rows.Add("Second Entry"); GridView1.DataSource = myTable; GridView1.DataBind(); } public void Gridview1_RowCommand(Object sender, GridViewCommandEventArgs e) { //set lblStatus.text to "Win", or "Fail" } </code></pre> <p>Thanks in advance!</p>
 

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