English 中文(简体)
清单:未启动的纽特项目
原标题:listview with button ItemCommand event not triggered
  • 时间:2012-01-16 10:00:30
  •  标签:
  • asp.net

我第一次使用<条码>ListView控制,建立了<条码>CommandName,使活动得以进行。

<编码> 清单: 当我点击纽顿时,应该启动,但不要。 在我点击时,没有发生任何事件。

<asp:ListView ID="ListView" runat="server" itemcommand="ListView_onItemCommand" 
            onitemcommand="ListView_ItemCommand">
            <EmptyDataTemplate>
                <table runat="server" 
                    style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <ItemTemplate>
                <tr style="background-color:#DCDCDC;color: #000000;">
                    <td style="text-align: center">
                        <asp:Label ID="NameLabel" runat="server" Text= <%# Eval("Name") %>  />
                    </td>
                    <td style="text-align: center">
                        <asp:Label ID="BirthdayLabel" runat="server" Text= <%# Eval("Birthday") %>  />
                    </td>
                    <td style="text-align: center">
                        <asp:Label ID="CourseNameLabel" runat="server" 
                            Text= <%# Eval("CourseName") %>  />
                    </td>
                       
                    <td style="text-align: center">
                        <asp:ImageButton ID="Edit" runat="server" ImageUrl="~/images/edit_icon.png" CommandName="Edit" OnClick="Edit_OnClick" />
                    </td>
                     <td style="text-align: center">
                         <asp:ImageButton ID="Delete" runat="server" ImageUrl="~/images/delete_icon.png" CommandName="Delete" CommandArgument="Delete" />
                    </td>
                </tr>
            </ItemTemplate>

protected void ListView_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        if (e.CommandArgument.ToString() == "Delete")
        {
            Label1.Text = "Edit From Button";
        }
    }
问题回答

1. 更改你的指挥名称,使其改为别的

 CommandName="Edit"

i.e.

CommandName="MyEdit"

指挥=“Edit”火灾 ListView_ItemEditing direct. 我认为这将掩盖项目界。 但是,TBH在我犯了这一错误时,由于失踪事件的传记员,它坠毁了该页。

So 解释2

The other explanation could be that you are rebinding the grid. This often causes events to seem to disappear. Check you re not doing this





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签