数据列表中链接按钮的Onclick事件 [英] Onclick Event of a linkbutton in datalist
本文介绍了数据列表中链接按钮的Onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试触发放置在数据列表中的链接按钮的Click事件,并且我正在使用以下代码
ASPX页面
I''m trying to fire the Click event of the linkbutton placed inside a datalist,and i''m using the following code
ASPX Page
<asp:LinkButton ID="LinkButton1" runat="server" Font-Names="Bertham" Font-Size="X-Large"
Font-Underline="False" CommandName = "answer">"<%#Eval ("Question") %>"</asp:LinkButton>
页面后面的代码
Code Behind Page
protected void DataList1_ItemCommand(object source,System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if (e.CommandName == "answer")
{
Response.Write("<script language = 'javascript'>alert('U Clicked The Linkbutton'</script>)");
Response.Write("Hello");
//Response.Write("Hello");
}
}
但它不起作用....
谁能帮我.我认为这是一个很大的问题2.我在网上尝试自己找出问题时发现的问题.
在此先感谢....
but its not working....
Can Anyone help me. I think this is a big problem 2 many. Which I found on net while trying to sought out the problem by myself.
Thanks In Advance....
推荐答案
很好的链接解决了我的问题http://csharp-guide.blogspot.in/2012/04/capture-button-click-events-in-datalist.html [ ^ ]
Well This Link Solved My Problem http://csharp-guide.blogspot.in/2012/04/capture-button-click-events-in-datalist.html[^]
如果只有一个条件,则可以删除if,并在grid databound event上执行此操作,因为当您使用item命令时,它会回发并在响应之后.
if you have only one condition, you can remove if , and do this on grid databound event , because when you use item command it post back and after it response you.
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton btn = (LinkButton) FindControl("lnkbtn");
btn.Attributes.Add("onclick","alert(you are leaving this page!)");
}
这篇关于数据列表中链接按钮的Onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文