2014-04-23 45 views
0

您好我有一個gridview在我的asp.net網頁是有界限的,用戶選擇3下拉列表後。
下拉列表的自動回發設置爲true,現在我的問題是當我在gridview ItemTemplate中放置一個按鈕,imagebutton或linkbutton時,onclick事件開始進行射擊! 這裏是我的代碼linkbutton或button onClick不在gridview內部激發ItemTemplate

<asp:GridView ID="GridView1" runat="server" Width="90%" Height="100%" OnRowCommand="GridView1_RowCommand" OnPageIndexChanging="GridView1_PageIndexChanging" style="margin:20px; vertical-align:top;" PageSize="10" AllowPaging="True" 
     AllowSorting="True" 
     AutoGenerateColumns="False" DataKeyNames="WFStudentID" ShowHeader="true" BorderWidth="1px"> 

     <Columns> 
      <asp:TemplateField ShowHeader="true"> 
      <ItemTemplate > 
       <tr> 
       <td> 
        <asp:Label ID="Label1" ForeColor="Silver" Font-Size="Medium" runat="server" Text='<%# Bind("Name") %>'></asp:Label> 
       </td> 
       <td> 
        <asp:Label ID="Label2" runat="server" ForeColor="Silver" Font-Size="Medium" Text='<%# Bind("Family") %>'></asp:Label> 
       </td> 
       <td> 
        <asp:HyperLink ID="HyperLink1" ForeColor="Silver" Font-Size="Medium" Target="_blank" NavigateUrl='<%# Bind("WFStudentFilePath") %>' runat="server">دانلود</asp:HyperLink> 
       </td> 
       <td> 
        <asp:Label ID="Label7" runat="server" ForeColor="Silver" Font-Size="Medium" Text='<%# Bind("WFStudentDate") %>'></asp:Label> 
       </td> 
       <td> 
        <asp:Button ID="Deny" Text="deny" OnClick="Deny_Click1"  runat="server" /> 
       </td> 
       <td> 
        <asp:ImageButton ID="accept" OnClick="accept_Click" runat="server" /> 
       </td> 
       <td> 
        <asp:TextBox ID="des" TextMode="MultiLine" Height="100px" Width="200px" runat="server"></asp:TextBox> 
       </td> 
       </tr> 
       <br /> 
      </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
    </asp:GridView> 



protected void Deny_Click1(object sender, EventArgs e) 
{ 
    Response.Redirect("home.aspx"); 
} 
+1

有你在這裏簽出的答案嗎? http://stackoverflow.com/a/11455262/382214 – ewitkows

+1

只是爲了仔細檢查......你是否在'Deny_Click1'的最頂端放置了一個斷點。你正在吞嚥潛在的例外,所以問題可能是有一個例外,但你沒有意識到這一點。 –

+0

@ClaudioRedi我把Response.redirect(「home.aspx」)它沒有開火! – Oli

回答

2

它可能是射擊,但它會拋出一個異常,(這你catch塊忽略)。例外是因爲這一行:

LinkBut​​ton Link =(LinkBut​​ton)sender;

發件人是一個按鈕,而不是一個LinkBut​​ton,所以演員無效,並會拋出一個異常。

+0

不,它不是一個例外看我的編輯 – Oli

0

GridView內的按鈕不響應直接事件。他們必須通過GridView的RowCommand事件實現。我已經看到你已經實施了OnRowCommand="GridView1_RowCommand"。所以,現在你需要做如下修改圖像按鈕:

<asp:ImageButton ID="accept" runat="server" CommandName="Accept" /> 

現在查找「接受」命令名在GridView1_RowCommand事件處理程序。

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "Accept") 
    { 
    // Your code goes here 
    } 

} 

我希望這會有所幫助。

+0

我試過了,但dosent工作! – Oli

+0

它不是命中GridView1_RowCommand事件處理程序嗎?它是否回傳? – NareshC

+0

你是錯的。 * GridView中的按鈕不直接響應事件*?從何時起?請不要提供錯誤信息! – naveen

相關問題