【问题标题】:Rowcommand not firing for linkbutton in gridview?Rowcommand 没有触发 gridview 中的链接按钮?
【发布时间】:2014-02-19 06:17:33
【问题描述】:

我有一个带有链接按钮的网格视图。我使用 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事件中设置lightbox的内容。我在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 没有触发所以灯箱显示没有数据。任何帮助表示赞赏。

【问题讨论】:

    标签: jquery asp.net css gridview


    【解决方案1】:

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

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

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

    2. 不要为GridView禁用ViewState

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

      &lt;asp:GridView OnRowCommand="Event_Handler_Here" .. /&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-11
      相关资源
      最近更新 更多