Datalist中的按钮单击事件 [英] Button click event in Datalist
本文介绍了Datalist中的按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I want a button click event inside a Datalist But I am not able to get so
this is my code
<pre lang="HTML"><asp:DataList ID="ArticleRep" runat="server" OnItemDataBound="ArticleRep_ItemDataBound"
BorderColor="WhiteSmoke" BorderStyle="Solid" BorderWidth="0px" GridLines="Both"
Width="100%" OnItemCommand="ArticleRep_ItemCommand">
<ItemTemplate>
<asp:DataList ID="OwnArticle" runat="server" OnItemDataBound="OwnArticle_ItemDataBound">
<ItemTemplate>
<table width="100%" cellpadding="3px" cellspacing="0">
<tr>
<td width="20%">
<asp:Image ID="img" runat="server" Height="50px" Width="45px" ImageUrl='<%#"~/UsingID.ashx?id="+ Eval("ID")%>' />
</td>
<td width="80%">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%">
<asp:HyperLink ID="hlink" runat="server">
</asp:HyperLink>
</td>
</tr>
<tr>
<td>
<asp:DataList ID="innerRepeater" runat="server">
<ItemTemplate>
<asp:Label ID="lbldesc" runat="server" Text='<%# Eval("Key").ToString()%>'></asp:Label>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="10%">
</td>
<td colspan="5" width="90%">
<asp:Label ID="lblArticleName" CssClass="lblCaptionGrey" runat="server" Text='<%# Eval("Article_Name").ToString()%>'></asp:Label>
</td>
</tr>
<tr>
<td width="10%">
</td>
<td colspan="5" width="90%">
<asp:Label ID="Label2" CssClass="lblPara" runat="server" Text='<%# Eval("Article_Desc").ToString()%>'></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnLike" CommandName="isLike" runat="server"
Text="Like" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
和代码隐藏是
and codebehind is
protected void ArticleRep_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "isLike")
{
Response.Write(@"<script language='javascript'>alert('success.');</script>");
}
else
Response.Write(@"<script language='javascript'>alert('Error.');</script>");
}
如何获得数据列表中按钮的按钮点击事件?
签出以上代码!! ??
how to get a button click event for the button inside a datalist?
checkout the above code!!??
推荐答案
<asp:button id="btnLike" commandname="isLike" runat="server" xmlns:asp="#unknown">
Text="Like" OnClick="btnLike_Click" /> </asp:button>
和代码背后:
and in Code behind :
protected void btnLike_Click(object sender, EventArgs e)
{
}
希望这是你想要的......
I had to call the binding of article method in !ISPOSTBACK condition
well thanks for ur suggestions
这篇关于Datalist中的按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文