Datalist没有得到正确的约束

时间:2013-11-21 07:08:42

标签: c# asp.net .net vb.net visual-studio-2008

我有以下datalist:

 <asp:DataList ID="dlMovieImages" runat="server" RepeatDirection="Horizontal" RepeatColumns="6"
                                    Width="100%">

                                    <ItemTemplate   >
                                        <div class="creamebox w49" id="inDiv" runat="server">
                                            <table width="95%" border="0" align="center" cellpadding="3" cellspacing="2" style="padding-top: 10px">
                                                 <tr>
                                                <td colspan="2" align="left" valign="top">
                                                     <asp:Label ID="lblMovieName" runat="server" CssClass="NormalTextBig" Visible="false">MovieName</asp:Label>                                                </td>

                                                </tr>
                                                <tr>

                                                   <td align="left" colspan="2" valign="top">
                                                     <asp:Image ID="imgSmall" runat="server" width="150" Height="200"  Visible="false"/> 
                                                   </td>
                                                </tr>
                                                <tr>
                                                <td colspan="2" align="left" valign="top">
                                                    <asp:FileUpload ID="FUImage" runat="server" CssClass="NormalText"  Visible="false"/>
                                                    <asp:LinkButton ID="lnkUpload" runat="server" CssClass="JustLinks" CommandName="Upload" CommandArgument='<%# Eval("MovieID") %>'  Visible="false">Upload</asp:LinkButton>
                                                </td>

                                                </tr>

                                            </table>
                                        </div>
                                    </ItemTemplate>
                                                                                                    </asp:DataList>

使用以下代码绑定它:

 If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then

                If rbMovies.SelectedValue = "0" Then
                    flag = True
                    If System.IO.File.Exists(Server.MapPath("~/MoviePoster/" & e.Item.DataItem("movieid") & "_L.jpg")) And System.IO.File.Exists(Server.MapPath("~/MoviePoster/" & e.Item.DataItem("movieid") & "_S.jpg")) Then
                        CType(e.Item.FindControl("lblMovieName"), Label).Text = e.Item.DataItem("movieid") & ". " & e.Item.DataItem("moviename")
                        CType(e.Item.FindControl("imgSmall"), System.Web.UI.WebControls.Image).ImageUrl = "~/MoviePoster/" & e.Item.DataItem("movieid") & "_S.jpg"
                    Else
                        TotalnoImage += 1
                        CType(e.Item.FindControl("lblMovieName"), Label).Text = e.Item.DataItem("movieid") & ". " & e.Item.DataItem("moviename")
                        CType(e.Item.FindControl("imgSmall"), System.Web.UI.WebControls.Image).ImageUrl = "~/MoviePoster/" & "no_image_S.jpg"
                    End If
                End If

                Dim divControl As HtmlGenericControl = TryCast(e.Item.FindControl("inDiv"), HtmlGenericControl)

                If rbMovies.SelectedValue = "1" Then
                    If System.IO.File.Exists(Server.MapPath("~/MoviePoster/" & e.Item.DataItem("movieid") & "_L.jpg")) And System.IO.File.Exists(Server.MapPath("~/MoviePoster/" & e.Item.DataItem("movieid") & "_S.jpg")) Then
                        divControl.Visible = False
                    Else
                        divControl.Visible = True
                        flag = True
                        TotalnoImage += 1
                        CType(e.Item.FindControl("lblMovieName"), Label).Text = e.Item.DataItem("movieid") & ". " & e.Item.DataItem("moviename")
                        CType(e.Item.FindControl("imgSmall"), System.Web.UI.WebControls.Image).ImageUrl = "~/MoviePoster/" & "no_image_S.jpg"
                    End If
                End If

                If flag = True Then
                    CType(e.Item.FindControl("imgSmall"), System.Web.UI.WebControls.Image).Visible = True
                    CType(e.Item.FindControl("lblMovieName"), Label).Visible = True
                    CType(e.Item.FindControl("FUImage"), FileUpload).Visible = True
                    CType(e.Item.FindControl("lnkUpload"), LinkButton).Visible = True
                End If

            End If

当rbMovies =“0”时,我想显示文件夹中的所有图像,当rbMovies =“1”时,只显示一个特定图像,即“noimage”。

当Datalist受到约束时,它会显示如下:

enter image description here

其中noimage不适用它显示空白项目,如第3和第10所示。

我希望它在一行中。

请帮助我。

1 个答案:

答案 0 :(得分:1)

尝试在具有属性display:hidden

的表上添加一个css类

mytable.hidden {visibility:hidden;}

还在表上添加一个runat =“server”并为其命名。 您可以在codebehind

中添加/删除cssclass