日期:2014-05-19  浏览次数:20449 次

菜鸟遇到控制datalist中删除按钮显示的奇怪问题
先谢谢各位大虾,能不能看看究竟问题出在哪里

本来目的:把datalist中本来隐藏的删除按钮显示出来

奇怪问题出现:总是最后一条记录的按钮不显示,其它的都能显示

代码:

<asp:DataList   ID= "DataList1 "   runat= "server "     DataKeyField   = "CommentId "   DataSourceID= "ObjectDataSource1 "   Width   =1020px   OnItemDataBound= "DataList1_ShowDeleteButton "     >
                <ItemTemplate>
    .......                    
    <asp:Button   ID= "BtDeleteComment "   runat= "server "   Text= "Delete "   CommandName   = "delete "   Visible   =false   />
                                                                        <asp:Label   ID= "CommentIdLabel "   runat= "server "   Text= ' <%#   Eval( "CommentId ")   %> '   Visible   =false   > </asp:Label>
.......
    </ItemTemplate>


Protected   Sub   DataList1_ShowDeleteButton(ByVal   sender   As   Object,   ByVal   e   As   DataListItemEventArgs)
                Dim   Item   As   DataListItem

                For   Each   Item   In   DataList1.Items
                        Dim   DeleteButton   As   Button   =   CType(Item.FindControl( "BtDeleteComment "),   Button)
                        DeleteButton.Visible   =   True


                Next
        End   Sub

再次谢谢,看哪位能不能告诉我一下,问题出在哪里?


------解决方案--------------------
加一句 if (item.ItemType=ListItemType.Item || item.ItemType==ListItemType.A...)