Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my code:

XML
<asp:SqlDataSource ID="dsCollections" runat="server" ConnectionString="<%$ ConnectionStrings:csConnectionString %>"
         SelectCommand="SELECT [CategName], [Id] FROM [Category]"></asp:SqlDataSource>
  <asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_Command" CommandName="MyUpdate" CommandArgument='<%# Eval("CategName") %>'>LinkButton</asp:LinkButton>
    </ItemTemplate>
</asp:Repeater>


asp.net code:

C#
protected void LinkButton1_Command(object sender, CommandEventArgs e)
   {
       if (e.CommandName == "MyUpdate")
       {
           Response.Write("work");
       }
   }
Posted
Updated 31-Dec-14 19:59pm
Comments
kedar001 1-Jan-15 2:19am    
add CausesValidation="false" in link button and then try.
Sergey Alexandrovich Kryukov 1-Jan-15 2:20am    
"Not working" is not informative. If you want anyone to even look at your code, you have to explain everything property: what do you want to achieve and how, what did you expect and what did you get instead, why do you feel it's wrong, and so on...
—SA
Member 11319592 1-Jan-15 23:46pm    
I try, but not working..,
Sergey Alexandrovich Kryukov 1-Jan-15 23:49pm    
Note that you repeated "not working" in response to my comment that "not working" in not informative. If you want to ridicule common sense, this site is not the best one for such things.
—SA
Member 11319592 2-Jan-15 0:02am    
Break point was not come to the item command code.,

i think you should bind the data from code behind...
because its working..
C#
DataTable dt = new DataTable();
           dt.Columns.Add("CategName");
           for (int i = 0; i < 10; i++)
           {
               dt.Rows.Add("CategName" + i);
           }
           Repeater1.DataSource = dt;
           Repeater1.DataBind();
 
Share this answer
 
If that is a Repeater Control, then you can try defining the Repeater.ItemCommand Event[^].
 
Share this answer
 
You forgot the OnItemCommand event in Repeater
Remove OnCommand="LinkButton1_Command"

C#
<asp:repeater onitemcommand="RepeaterCommandEventHandler" xmlns:asp="#unknown" />


in your example

ASP.NET
<asp:repeater id="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand">
    <itemtemplate>
        <asp:linkbutton id="LinkButton1" runat="server" commandname="MyUpdate" commandargument="<%# Eval("CategName") %>">LinkButton</asp:linkbutton>
    </itemtemplate></asp:repeater>


in .cs

C#
protected void Repeater1_ItemCommand(object sender, RepeaterCommandEventArgs e)
    {
      
      if (e.CommandName == "MyUpdate")
        {
           
        }
    }
 
Share this answer
 
v2

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