2016-03-24 58 views
0

所以我有一個imagebutton的gridview,事情是它永遠不會觸發。我不知道爲什麼。這裏是代碼。gridview上的圖像按鈕不觸發asp.net

<asp:GridView ID="GridView1" runat="server" Width="233px" 
    OnCommand="GridView1_RowCommand" onrowcommand="GridView1_RowCommand" 
    DataKeyNames="Nombre"> 
    <Columns> 
     <asp:TemplateField HeaderText="" ItemStyle-Width="12%" ItemStyle- 
      HorizontalAlign="Center" > 
      <ItemTemplate> 
       <asp:ImageButton ID="lnkEditar" runat="server" CommandName="Edit" 
        ImageUrl="Imagenes/edit.png" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

和後面的代碼:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "Edit") 
    { 
     int index = Convert.ToInt32(e.CommandArgument); 
     Label1.Text = GridView1.Rows[index].Cells[2].ToString(); 
    } 
} 

我調試它,它永遠不會觸發RowCommand事件。感謝任何幫助!

+0

? – Webruster

回答

0

嘗試改變,因爲你使用的UpdatePanel遵循OnRowCommand

OnRowCommand="GridView1_RowCommand" 
+0

@nahuel並嘗試將命令名更改爲'Edit1'並檢查一次 – Webruster

相關問題