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>
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>"); }
<asp:button id="btnLike" commandname="isLike" runat="server" xmlns:asp="#unknown"> Text="Like" OnClick="btnLike_Click" /> </asp:button>
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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)