【问题标题】:Linkbutton's event in GridView not firing its event on 2nd TimeGridView 中的链接按钮事件未在第二次触发其事件
【发布时间】:2013-02-22 10:45:36
【问题描述】:

似乎是一个奇怪的问题,但我在GridView 中的Linkbutton 没有在2nd Time. 上触发其事件
详细说明:
我有一个GridView,其中有linkButton,它正在触发一个事件。此事件在 第一次 时完美触发,但当我在 第二次 时单击它时不起作用(不回发)。

<asp:GridView ID="dg1" runat="server" OnSorting="dg1_Sorting" OnRowCreated="GridViewSortImages"
   SkinID="grid" Width="100%" Font-Underline="false" HeaderStyle-Font-Underline="false"
   OnRowCommand="dg1_RowCommand" AllowPaging="True" HeaderStyle-HorizontalAlign="Left"
   OnRowDataBound="dg1_RowDataBound" ShowFooter="true">
            <Columns>
              <asp:TemplateField ItemStyle-Width="15px">
                <ItemTemplate>
                    <asp:ImageButton ID="imgbtndel" runat="server" OnClick="imgbtndel_Click" ImageUrl="~/css/Images/delete.gif"
                            OnClientClick="return confirm('Do you want to Delete')"></asp:ImageButton>
                    </ItemTemplate>
                    <ItemStyle Width="15px" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Account Type ID" SortExpression="ID" ItemStyle-Width="60px"
                    HeaderStyle-Font-Underline="false">
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkbtnno" runat="server" ForeColor="#123B61" Text='<%#Eval("ID") %>'
                            OnClick="lnkbtnno_Click"></asp:LinkButton>
                    </ItemTemplate>
                    <HeaderStyle Font-Underline="False" />
                    <ItemStyle Width="60px" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Description" SortExpression="Description" ItemStyle-Width="200px">
                    <ItemTemplate>
                        <asp:Label ID="lblDesc" runat="server" Text='<%#Eval("Description") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle Width="200px" />
                    <HeaderStyle HorizontalAlign="Left" />
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

C#

protected void lnkbtnno_Click(object sender, EventArgs e)
{

    LinkButton lnkbtn = sender as LinkButton;
    txtaccid.Text = lnkbtn.Text;

    Label lblDesc = lnkbtn.FindControl("lblDesc") as Label;
    txtdesc.Text = lblDesc.Text;

}

【问题讨论】:

  • 你能展示负责gridveiw数据绑定的代码吗?

标签: asp.net gridview hyperlink


【解决方案1】:

您的链接按钮第二次未触发事件。因为第二次触发了其他一些事件而不是您的链接按钮。所以在事件堆栈链接按钮事件被禁用。检查您添加的动态控制是否正在触发。使用 firebug(F12) 等开发者工具

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多