Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
C#
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

C#
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!!??
Posted
Updated 6-Aug-13 19:46pm
v5
Comments
Nirav Prabtani 5-Aug-13 8:21am    
what is the problem???
naveend915 5-Aug-13 8:33am    
how to get a button click event for the button inside a datalist?

checkout the above code!!
Naz_Firdouse 5-Aug-13 8:51am    
when you click on button,are you not getting success alert message?
naveend915 5-Aug-13 9:04am    
yup am not getting that msg? what is to be done?

<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)
   {

   }

hope this is you want ...
 
Share this answer
 
v2
Comments
naveend915 5-Aug-13 8:42am    
nope i wanted

how to get a button click event for the button inside a datalist?

checkout the above code!!
C#
I had to call the binding of article method in !ISPOSTBACK condition

well thanks for ur suggestions
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900