Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, i want to get button in listview control, but i don't know, how to do it.
My ASP.NET CODE:
C#
<asp:ListView ID="lv_Links" runat="server" >

           <LayoutTemplate>
               <ul style="list-style: none;">
                   <asp:PlaceHolder ID="ItemPlaceholder" runat="server" />
               </ul>
           </LayoutTemplate>
           <ItemTemplate>
                <ul style="list-style: none;padding: 0;">
                  <li> <asp:HyperLink ID="LinkItem" runat="server" Text='<%# Eval("Description") %>'
                            NavigateUrl='<%# Eval("Link") %>'>
                            </asp:HyperLink>&nbsp;<asp:ImageButton ID="Button2" ImageUrl="~/_layouts/Portal.Croc.Box.Social.ForNewEmployee/i/delete.gif" itemid='<%# Eval("ID") %>'  OnClick="delete_Onclick" OnClientClick="return confirm('Вы действительно хотите удалить ссылку?');" Width="14px" Height="14px" runat="server"/> </li>

                  </ul>
               </ItemTemplate>
       </asp:ListView>



Code Behind:

C#
protected void Page_Load(object sender, EventArgs e)
       {
           SPWeb oWebs = SPContext.Current.Web;
               String Editors = "Новому сотруднику – модераторы";
           String Owners = oWebs.Site.RootWeb.AssociatedOwnerGroup.ToString();
           if (oWebs.SiteGroups[Editors].ContainsCurrentUser || oWebs.SiteGroups[Owners].ContainsCurrentUser)
           {
               HyperLink1.Visible = true;
               foreach (ListViewItem item in lv_Links.Items)
               {
                   ImageButton ddrList = (ImageButton)item.FindControl("Button2") as ImageButton;
                   ddrList.Visible = true;

               }
           }
           else
           {

           }
        }


But it doesn't work:(Help
Posted
Updated 12-Aug-13 22:38pm
v2
Comments
pradiprenushe 13-Aug-13 4:31am    
What error you get? You got null value?
Ankur\m/ 13-Aug-13 8:04am    
[moved from direct comment]
Alexrf wrote - 3 hrs ago
yes, when debug it is null
pradiprenushe 13-Aug-13 8:43am    
Two case possible
1. If execution not going in foreach then you binding listview afterward
2. Check for item type before finding button
pradiprenushe 13-Aug-13 8:46am    
Like this
if((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
{
ImageButton ddrList = (ImageButton)item.FindControl("Button2") as ImageButton;
}
Ankur\m/ 13-Aug-13 8:03am    
The answerer has left a reply for you. Please check. Also, hit reply button beside the comment to reply to the user. That notifies him about the comment.

1 solution

 
Share this answer
 
Comments
Ankur\m/ 13-Aug-13 5:04am    
[copied from answer]
OP wrote:
Hi, Ridoy, thx for your answer, but i want to hide button, in page_load event, how to do it?
ridoy 13-Aug-13 6:58am    
in your page load event set visibility of your button to hidden or collapsed.

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