Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here you go...</p> <pre><code>public void Gridview1_RowCommand(Object sender, GridViewCommandEventArgs e) { lblStatus.Text = e.CommandName; } </code></pre> <p>I see that there is more to this question than is answered here, bear with me. One way would be to delegate the <code>OnCommand</code> event of each button to its designated event handler, as follows:</p> <pre><code>&lt;div&gt; &lt;asp:GridView ID="MyGridView" runat="server" EnableModelValidation="true" AutoGenerateColumns="False"&gt; &lt;Columns&gt; &lt;asp:TemplateField ShowHeader="False"&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID="MyWinButton" runat="server" OnCommand="MyWinButton_OnCommand" CommandName="Win" Text="Win" /&gt; &lt;asp:Label ID="MyStatusLabel" runat="server" Text='&lt;%# Bind("text") %&gt;'/&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/div&gt; public void MyWinButton_OnCommand(Object sender, CommandEventArgs e) { var label = ((Button)sender).Parent.FindControl("MyStatusLabel") as Label; label.Text = e.CommandName; } </code></pre> <p>Also, as Alison suggests, you won't see the desired output of this unless you use <code>!IsPostBack</code> in <code>Page_Load</code>. Furthermore, on doing so this does in fact enable you to use the one row command event handler as initially suggested, albeit with a slight change in the label retrieval:</p> <pre><code>public void MyGridView_OnRowCommand(Object sender, GridViewCommandEventArgs e) { var label = ((Button)e.CommandSource).Parent.FindControl("MyStatusLabel") as Label; label.Text = e.CommandName; } </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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