DataList的SelectedItemTemplate内的按钮 [英] button inside SelectedItemTemplate of DataList
问题描述
我有一个DataList,并且SelectedItemTemplate里面有一个按钮.
< asp:按钮ID ="getDetails"符文=>服务器文本="发送查询"CommandName =" SendEnquiry字体名称=" verdana字体大小=" 8pt高度=" 20px宽度=" 90px"/>
单击此按钮后,我应该知道该按钮引发了该事件.为此,我编写了以下代码.
I have a DataList and inside the SelectedItemTemplate there is a button.
<asp:Button ID="getDetails" runat ="server" Text ="Send Enquiry" CommandName ="SendEnquiry" Font-Names ="verdana" Font-Size ="8pt" Height ="20px" Width ="90px" />
When this button is clicked I should know wheather the event is raised by this button. For this purpose I had written the following code.
protected void carList_ItemCommand(object sender, DataListCommandEventArgs e)
{
try
{
if(e.CommandName =="SendEnquiry")
{
Label12.Text = "Send Enquiry";
}
else
{
Label12.Text ="Do not send";
}
}
catch (Exception e1)
{
Label12.Text = e1.Message.ToString();
}
}
但是,当我单击此按钮时,上述条件就永远不会成为现实.任何人都可以告诉我什么地方出了问题.
But when I click this button the above condition is never becoming true. Can anyone tell what is wrong.
Thanks in advance!
推荐答案
我想知道的第一件事就是为什么需要在数据列表中保留按钮.
这样做的目的是什么?
first thing i would like to know is why you need to keep button in datalist.
what is your purpose behind doing that
将Asp:Button
转换为Asp:LinkButton
.会工作的.
即:
Convert theAsp:Button
into anAsp:LinkButton
. It will work.
That is:
<asp:LinkButton ID="getDetails" runat="server" Text="Send Enquiry" CommandName="SendEnquiry" Font-Names="verdana" Font-Size="8pt" Height="20px" Width="90px" />
或者,您必须对Asp:Button
使用UseSubmitBehavior="false"
属性,以使其起作用.即:
Or, you have to use the UseSubmitBehavior="false"
property for the Asp:Button
, to make it work. That is:
<asp:Button ID="getDetails" runat="server" Text="Send Enquiry" UseSubmitBehavior="false" CommandName="SendEnquiry" Font-Names="verdana" Font-Size="8pt" Height="20px" Width="90px" />
原因是,默认情况下,Asp:Button
呈现提交"按钮,如果DataList
具有提交行为,则DataList
不起作用.因此,您需要标记UseSubmitBehavior="false"
祝你好运:)
The reason is, by default an Asp:Button
renders an Submit button and DataList
doest not work if the button has a Submit behaviour. So, you need to mark the UseSubmitBehavior="false"
Good luck :)
这篇关于DataList的SelectedItemTemplate内的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!