Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have a DataList control in my aspx page. It consist a linkbutton and label. I want that on clicking link button the link button get hide and label become visible. I have tried like this but failed. Please guide.
C#
protected void DataList4_ItemCommand(object source, DataListCommandEventArgs e)
   {
       if (e.CommandName == "lnkhead")
       {
           LinkButton lnk = (LinkButton)e.CommandSource;

           foreach (DataListItem item in DataList4.Items)
           {
               Label lbl = (Label)item.FindControl("lblhead");
               lbl.Visible = true;

           }
               lnk.Visible = false;

       }
   }
Posted
Updated 22-Dec-10 23:05pm
v2

1 solution

Remove foreach block
protected void DataList4_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "lnkhead")
        {
            LinkButton lnk = (LinkButton)e.CommandSource;            
            Label lbl = (Label)e.Item.FindControl("lblhead");
            lbl.Visible = true;
            lnk.Visible = false;
           
        }
    }
 
Share this answer
 
v2
Comments
mylogics 23-Dec-10 6:12am    
Label lbl = (Label)item.FindControl("lblhead");
this line does not works...bcoz it takes items not item after (Label)
m@dhu 23-Dec-10 6:18am    
Updated the answer check the bold.

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