2013-12-23 49 views
0

我创建了一个ListView,我在其中插入了一列我想在ItemCommand事件中触发的按钮,但是当我按下按钮时,我获得了一个页面加载但没有任何反应(Event ItemCommand don不会着火)。Listvew ItemCommand not fire

<asp:ListView ID="ListView_documenti" runat="server" OnLoad="carica_ListView" OnItemCommand="esegui_comando"> 
<LayoutTemplate> 
    <table id="Table1" runat="server" class="ListViewUCSS"> 
     <tr id="Tr1" runat="server"> 
      <td id="Td1" runat="server"> 
       <table ID="itemPlaceholderContainer" runat="server" border="0" style="" > 
        <tr id="Tr2" runat="server" class="ListViewUHEADER"> 
         <th id="Th0" runat="server" style="width:40%">Nome File</th> 
         <th id="Th3" runat="server" style="width:20%">Vedi</th>        
        </tr> 
        <tr ID="itemPlaceholder" runat="server"></tr> 
       </table> 
      </td> 
     </tr> 
     <tr id="Tr3" runat="server"> 
      <td id="Td2" runat="server" style=""> 
      </td> 
     </tr> 
    </table> 
</LayoutTemplate> 
<ItemTemplate> 
    <tr class="ListViewUTENTI"> 
     <td><asp:Label ID="nomeLabel" runat="server" Text='<%# Eval("nome") %>' /></td> 
     <td><asp:button ID="vediDocButton" runat="server" Text="Vedi documento" CommandName="vedi_doc" /></td>    
    </tr> 
</ItemTemplate> 
<AlternatingItemTemplate> 
    <tr class="ListViewUTENTIALTERNATING"> 
     <td><asp:Label ID="nomeLabel" runat="server" Text='<%# Eval("nome") %>' /></td> 
     <td><asp:button ID="vediDocButton" runat="server" Text="Vedi documento" CommandName="vedi_doc" /></td>   
    </tr> 
</AlternatingItemTemplate> 
<EmptyDataTemplate> 
    <table id="Table1" runat="server" style=""> 
     <tr> 
      <td>Nessun documento caricato per il seguente trust.</td> 
     </tr> 
    </table> 
</EmptyDataTemplate>  

,这是后面的代码部分在ItemCommand事件

protected void esegui_comando(object sender, ListViewCommandEventArgs e) 
    { 
     ListViewItem item = e.Item; 
     Label etichetta = (Label)item.FindControl("nomeLabel"); 
     etichetta = (Label)e.Item.FindControl("nomeLabel"); 
     //a questo punto capisco che button ha scatenato l'evento 
     switch(e.CommandName) 
     { 
      case "vedi_doc": 
       //indirizzo la pratica verso la pagina di visione delle pratiche 
       Response.Redirect("../scarica_documento.aspx?n=" + etichetta+"&c="+cartella); 
       break; 

     } 
    } 
+0

你在哪里以及如何在代码隐藏中绑定你的列表视图?您是否在每次加载页面时重新绑定它? –

+0

我绑定onLoad事件(使用函数“carica_ListView)我的ListView并在每页加载时触发 –

+0

现在我将”carica_ListView“函数移动到init事件并且ItemCommand事件工作 –

回答

1

相关的你也可以改变你的onload事件代码:

protected void carica_ListView(object sender, EventArgs e) 
{ 
    if (!Page.IsPostBack) 
    { 
    //Your code 
    } 
} 

这将防止回发时重新绑定ListView。