[英]Make div clickable and use CommandName=“Select”
This code below works fine, when I click on the LinkButton
the select will get fired. 下面的代码工作正常,当我单击
LinkButton
,选择将被触发。
However I have a hover style on the div
so that it will change color if the mouse enters. 但是我在
div
上有一个悬停样式,以便在鼠标进入时它将更改颜色。 This is confusing for users because when they click on the div
nothing happens, only when they click on the LinkButton
. 这使用户感到困惑,因为当他们单击
div
时,只有当他们单击LinkButton
时,什么都不会发生。
I want the CommandName="Select"
to fire when a user clicks on the div
. 我希望在用户单击
div
时触发CommandName="Select"
。 How can I do this? 我怎样才能做到这一点?
<ItemTemplate>
<div class="Card">
<h4>
<asp:LinkButton ID="SelectButton" Text='<%# Eval("Name") %>' CommandName="Select" runat="server"/>
</h4>
<asp:Label runat="server" Text='<%# Eval("date") %>' />
<asp:Label runat="server" Text='<%# Eval("location") %>' />
<br />
</div>
</ItemTemplate>
You can use jquery
to trigger click event of button on click of the div 您可以使用
jquery
在div单击时触发按钮的click事件
$("#Card").click(function(){
$("[id$=SelectButton]").trigger('click');
});
I fixed my issues by placing the LinkButton
outside the div
. 我通过将
LinkButton
放置在div
之外来解决了我的问题。 Now the whole div
is clickable in the DataList
. 现在,整个
div
在DataList
都可以单击。
<ItemTemplate>
<asp:LinkButton CommandName="Select" runat="server">
<div class="Card">
<h4>
<asp:Label runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</h4>
<asp:Label runat="server" Text='<%# Eval("date") %>' />
<asp:Label runat="server" Text='<%# Eval("location") %>' />
<br />
</div>
</asp:LinkButton>
</ItemTemplate>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.