我有一个带链接按钮的 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 不显示任何数据。感谢任何帮助。
最佳答案
这种行为可能有不止一个原因。执行以下检查:
不要绑定(bind)您的
GridView
关于Page_Load
中的回发事件。意思是说如果你从后面的代码绑定(bind)你的 GridView,只在第一次绑定(bind)它::如果((!Page.IsPostback)){ GridView1.DataBind();
不要禁用
ViewState
对于GridView
最后一个选项和最不期望的是
OnRowCommand
属性可能缺失/不存在 在 gridView 标记中定义。确保您已经为 Row Command 事件定义了一个事件处理程序,例如:<asp:GridView OnRowCommand="Event_Handler_Here" .. />
关于jquery - Rowcommand 没有为 gridview 中的 linkbutton 触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21872598/