2012-01-09 78 views
0

圖像按鈕事件不會解僱我失去了從我的代碼 東西上ItemCommand事件不會觸發,請幫助我,我在這 stucked這是我DataList控件代碼:圖像按鈕事件不工作

<asp:DataList ID="DataList1" runat="server" RepeatColumns="1" 
    RepeatDirection="Vertical" Width="100%" 
    onitemdatabound="DataList1_ItemDataBound" onitemcommand="DataList1_ItemCommand"> 
    <ItemTemplate> 
    <div class="comments_pannel_top"> 
    <h2>Highly Recommended,</h2> 
    <p>By:<a href="#"><asp:Label ID="lblCustomerName" runat="server"></asp:Label></a> – 
     <asp:Label ID="lblCity" runat="server"></asp:Label>, 
     <asp:Label ID="lblCountry" runat="server"></asp:Label> <span> 
      <asp:Label ID="lblDate" runat="server"></asp:Label></span></p> 
    </div> 
    <div class="stars_1"> 
    <img src="images/favourities_icon.jpg" width="12" height="12" alt="" /> 
    <img src="images/favourities_icon.jpg" width="12" height="12" alt="" /> 
    <img src="images/favourities_icon.jpg" width="12" height="12" alt="" /> 
    <img src="images/favourities_icon.jpg" width="12" height="12" alt="" /> 
    <img src="images/favourities_icon.jpg" width="12" height="12" alt="" /> 
    </div> 
    <div class="comment"> 
    <p><strong>5 out of 11 people found this review helpful.</strong></p> 
    <p> 
     <asp:Label ID="lblReview" runat="server"></asp:Label></p> 
    </div> 
    <div class="report_abuse"> 
    <p>Did you find this review helpful?</p> 
    </div> 

    <div class="comments_pannel_bottom"> 
    <div class="btns"> 
     <asp:ImageButton ID="btnYes" ImageUrl="images/yes_btn.jpg" width="33" height="23" runat="server" CommandName="Yes" /> 
     <asp:ImageButton ID="btnNo" runat="server" ImageUrl="images/no_btn.jpg" width="33" height="23" alt="" CommandName="No"/> 

    </div> 
    </div> 
    </ItemTemplate> 
</asp:DataList> 

    This is the onitem command event handler: 

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) 
    { 

    } 

回答

1

它們綁定了什麼服務器端事件處理程序?通常,標記包含將命令事件綁定到服務器端處理程序的OnCommand屬性。見例子here

<asp:ImageButton id="imagebutton2" runat="server" 
     AlternateText="Edit" 
     ImageUrl="images/pict2.jpg" 
     OnCommand="ImageButton_Command" 
     CommandName="Edit"/> 

OnCommand屬性的值將是服務器端的事件處理程序方法的名稱:

void ImageButton_Command(object sender, CommandEventArgs e) 
{ 
    //... 
}