【问题标题】:Delete linkbutton not firing inside a gridview inside an update panel删除链接按钮未在更新面板内的网格视图内触发
【发布时间】:2010-09-10 15:56:38
【问题描述】:

查看了这里的各种帖子,但找不到一个非常喜欢它的帖子,我知道这将是一件小事,但我就是想不通。

我在更新面板中使用网格视图。 gridview 使用自动生成的删除列转换为模板字段列。代码如下:

<asp:GridView ID="gvFiles" runat="server" AutoGenerateColumns="False" 
        CellPadding="4"
        ForeColor="#333333" GridLines="None">
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
            <asp:TemplateField HeaderText="Files" HeaderStyle-HorizontalAlign="Left">

            <ItemStyle Width="210px" />
            <ItemTemplate>
                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Eval("Id", "~/Download.aspx?id={0}")%>'><%#Eval("LinkName")%></asp:HyperLink>,<br />
                Last Modified: <%#Me.cutDate(Eval("DateModified"))%>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ShowHeader="False" HeaderText="Team">
            <ItemStyle Width="150px" />
            <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
                <ItemTemplate>
                    <%#Me.GetTeamName(Eval("TeamId"))%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" 
                        CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this post?');"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>

        </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>

当它不在更新面板中时,我得到了完全相同的代码。我需要做什么才能让它工作?

编辑:忘了说,我的更新面板设置都是默认的。还有就是点击删除,弹出确认信息,点击是,然后什么也没有发生。

【问题讨论】:

  • 你是否在 onCommand 的事件处理程序中捕捉到了这个事件???
  • 不,我应该是吗?为什么只有在更新面板内才需要特定的事件句柄?

标签: .net gridview updatepanel


【解决方案1】:

我只在编辑按钮上遇到了同样的问题,所有其他的都很好,我认为这很奇怪。所以我在编辑按钮上添加了一个 onclick 事件来反弹 gridview 并且它起作用了。通过断点,我看到 gridview 在第一次单击时正确设置了 editIndex,但直到第二次单击才更改为 editItem 模板。希望这能给你一些想法。

【讨论】:

    【解决方案2】:

    我想你必须添加这个

    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnFindOrder" EventName="Click" />
    </Triggers>
    

    【讨论】:

    • 我假设 ControlID 应该是“lbDelete”,我试过了,但它说A control with ID 'lbDelete' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
    • lbDelete 在 gridview 中,这意味着它的 id 为 ctrl001_gvFiles_(something)_lbDelete。是这样的。运行该页面,然后查找 lbDelete。但是,这个问题是创建的每一行都有一个不同的 lbDelete ID,它应该增加它。
    猜你喜欢
    • 2011-11-30
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    相关资源
    最近更新 更多