jquery - Rowcommand 没有为 gridview 中的 linkbutton 触发?

标签 jquery asp.net css gridview

我有一个带链接按钮的 GridView 。我使用 jquery 和 css 为链接按钮设置了一个灯箱。

链接按钮源代码

<asp:TemplateField HeaderText="Course" ItemStyle-CssClass="course" HeaderStyle-CssClass="course">
                <ItemTemplate>
                    <asp:LinkButton ID="Course_Name" runat="server"   Text='<%# Eval("Course_Name__c") %>' ForeColor="#666699" CommandName="course" CommandArgument='<%# ((GridViewRow) Container).RowIndex %>'  ></asp:LinkButton>
                </ItemTemplate>
                <HeaderStyle Font-Bold="True" />

                <HeaderStyle HorizontalAlign="Center"/>
                <ItemStyle CssClass="course"></ItemStyle>
            </asp:TemplateField>

我必须在 rowcommand 事件中设置灯箱的内容。我在 rowdatabound 中使用以下代码。

  cname.CssClass = "popup-with-zoom-anim";
        cname.Attributes.Add("href", "#smalldialog");

脚本是,

    <script type="text/javascript">
    $(document).ready(function () {
        $('.popup-with-zoom-anim').magnificPopup({
            type: 'inline',

            fixedContentPos: false,
            fixedBgPos: true,

            overflowY: 'auto',

            closeBtnInside: true,
            preloader: false,

            midClick: true,
            removalDelay: 300,
            mainClass: 'my-mfp-zoom-in'
        });

        $('.popup-with-move-anim').magnificPopup({
            type: 'inline',

            fixedContentPos: false,
            fixedBgPos: true,

            overflowY: 'auto',

            closeBtnInside: true,
            preloader: false,

            midClick: true,
            removalDelay: 300,
            mainClass: 'my-mfp-slide-bottom'
        });
    });
</script>

但是 rowcommand 没有触发,所以 lightbox 不显示任何数据。感谢任何帮助。

最佳答案

这种行为可能有不止一个原因。执行以下检查:

  1. 不要绑定(bind)您的 GridView关于 Page_Load 中的回发事件。意思是说如果你从后面的代码绑定(bind)你的 GridView,只在第一次绑定(bind)它::

    如果((!Page.IsPostback)){ GridView1.DataBind();

  2. 不要禁用 ViewState对于 GridView

  3. 最后一个选项和最不期望的是 OnRowCommand属性可能缺失/不存在 在 gridView 标记中定义。确保您已经为 Row Command 事件定义了一个事件处理程序,例如:

    <asp:GridView OnRowCommand="Event_Handler_Here" .. />

关于jquery - Rowcommand 没有为 gridview 中的 linkbutton 触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21872598/

相关文章:

javascript - 一次打开一行详细信息数据表?

css - 为什么 Sass 好?

javascript - 在 jquery 中附加 div,并在字段中添加引号

javascript - 单击按钮运行功能 - 不起作用?

javascript - 如何在打印时隐藏 Jquery 多选

asp.net - 使用 System.Net.Mail 处理 Global.cs 错误

asp.net - ASP.NET 中的 <% %>(嵌入代码块)

c# - 如何在 C#/ASP.NET 中检查图像是否存在于 http ://someurl/myimage. jpg

没有 jQuery Masonry 插件的 css 网格不均匀高度

html - 让表格填满整个窗口