0

我有一个列表视图,它包含一个位图(图像按钮)和视频的详细信息。当我加载页面时,此列表应填充。将填充视频剪辑的所有详细信息,但不显示任何图像。我将图像和视频存储在一个文件夹中,并将图像的路径存储在 sql 数据库中。如何在 imagebutton 中填充图像?这就是我所做的:

    <asp:ListView runat="server" ID="lvlist" >
                        <LayoutTemplate>
                            <div id="itemPlaceholder" runat="server" />
                        </LayoutTemplate>
                        <ItemTemplate>
                               <br />
                               <div style="height:100px;">
                                    <a href="PlayVideo.aspx?vid=<%# DataBinder.Eval(Container.DataItem, "ID") %>">
                              <asp:ImageButton id="imgVidThumbnail" runat="server" AlternateText="Watch"
                                     ImageAlign="left" Width="150" Height="120px" style="margin-bottom:10px;  margin-left: 32px; margin-right:15px;"
                                     ImageUrl='<%#Eval("ThumbPath") %>' CommandArgument='<%#Eval("ThumbPath") %>'/>
                                       </a>
                                   <asp:Label ID="Label4" runat="server" Text="Title: " CssClass="ltrTitle" Width="100px" ></asp:Label>
                                   <asp:Label ID="ltrTitle" runat="server" Text='<%#Eval("FileTitle") %>' CssClass="ltrTitle" Width="300px" ></asp:Label>
                                   <br />
                                   <asp:Label ID="Label2" runat="server" Text="Date Uploaded: " CssClass="ltrTitle" Width="100px" ></asp:Label>
                                   <asp:Label ID="ltrDateUploaded" runat="server" Text='<%#Eval("DateUploaded") %>' CssClass="ltrTitle" Width="200px" ></asp:Label>
                                   <br />
                                   <asp:Label ID="Label3" runat="server" Text="Description: " CssClass="ltrTitle" Width="120px" ></asp:Label>
                                   <div id="div" style="overflow-x:auto; overflow-y:auto; width:75%; max-width:75%; height:55px; max-height:55px; word-break:break-all; background-color:ghostwhite;" runat="server"> 
                                   <asp:Label ID="ltrDescription" runat="server" Text='<%#Eval("Description") %>' CssClass="ltrTitle" Width="75%" ></asp:Label>
                                   </div>
                               </div>
                               <br /> <br />
                        </ItemTemplate>
                    </asp:ListView>

    private void BindList()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RoadHogzConnectionString"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("Select * from VideoInfo", con);
        cmd.ExecuteNonQuery();
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        adp.Fill(ds, "Video");
        Session["videos"] = ds;
        lvlist.DataSource = GetVideoList("Select * FROM VideoInfo");
        lvlist.DataBind();
    }

任何帮助将不胜感激!

编辑:路径将逐月更改..唯一保持不变的部分是上传和最后一个文件夹:文件夹路径将类似于 \uploads\Year\Month\thumb - 月份和年份将每月更改,并且每年.....

编辑:我的路径视图源给出了额外的字符:这是在此处显示图像的方法,然后它给了我以下代码: ImageUrl ='<%= ResolveClientUrl(Eval("ThumbPath"))%>'

    <a href="PlayVideo.aspx?vid=1038">
                              <input type="image" name="ctl00$MainContent$lvlist$ctrl1$imgVidThumbnail" id="MainContent_lvlist_imgVidThumbnail_1" src="<%=%20ResolveClientUrl(Eval("ThumbPath"))%>" alt="Watch" align="left" style="height:120px;width:150px;margin-bottom:10px;  margin-left: 32px; margin-right:15px;" />
                                       </a>

有了这个 ImageUrl='<%#Eval("ThumbPath") %>' 它在源视图中显示正确的路径,但仍然没有图像......

4

1 回答 1

0

将路径保存为没有服务器映射路径的虚拟路径。~/.. 而不是 c:/,其余代码工作正常。

于 2013-06-06T09:07:14.100 回答