本文介绍了使用数据库中的路径填充列表视图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个listview,它包含一个位图(imagebutton)和视频细节。当我加载页面时,该列表应该填充。视频剪辑的所有详细信息都会填充,但不会显示任何图像。我将图像和视频存储在一个文件夹中,并将图像的路径存储在sql数据库中。如何填充图像按钮中的图像?这就是我所做的: < asp:ListView runat = server ID = lvlist > < LayoutTemplate > < div id = itemPlaceholder runat = server / > < / LayoutTemplate > < ItemTemplate > < br / > < div style = 身高:100px; > < a href = PlayVideo.aspx?vid = <%#DataBinder.Eval(Container.DataItem, ID)%> > < asp:ImageButton id = imgVidThumbnail runat = server AlternateText = 观看 ImageAlign = left 宽度 = 150 高度 = 120px style = margin-bottom:10px; margin-left:32px; margin-right:15px; ImageUrl =' <% = ResolveClientUrl( Eval( ThumbPath))%>' CommandArgument =' <% = ResolveClientUrl(Eval( ThumbPath))%>' / > < / a > < asp:标签 ID = Label4 runat = server 文字 = 标题: CssClass = ltrTitle 宽度 = 100px > < / asp:标签 > < asp:标签 ID = ltrTitle runat = 服务器 文字 =' <% #Eval( FileTitle)%>' CssClass = ltrTitle 宽度 = 300px > < / asp:标签 > < ; br / > < asp:Label ID = Label2 runat = server Text = 上传日期: CssClass = ltrTitle 宽度 = 100px > < / asp:标签 > < asp:标签 ID = ltrDateUploaded runat = 服务器 文本 =' <% #Eval( DateUploaded)%>' CssClass = ltrTitle 宽度 = 200px > < / asp:标签 > < br / > < asp:标签 ID = Label3 runat = server 文本 = 描述: CssClass = ltrTitle 宽度 = 120px > < / asp:Label &g t; < div id = div style = 溢出 - X:汽车;溢出-Y:汽车;宽度:75%;最大宽度:75%;高度:55像素;最大高度:55像素;字断:盈亏所有; background-color:ghostwhite; runat = server > < asp:Label ID = ltrDescription runat = server 文字 =' <% #Eval( 描述)%>' CssClass = ltrTitle 宽度 = 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( 选择*来自VideoInfo,con); cmd.ExecuteNonQuery(); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds, 视频); 会话[ videos] = ds; lvlist.DataSource = GetVideoList( Select * FROM VideoInfo); lvlist.DataBind(); } 路径将逐月变化..保持不变的唯一部分是上传和最后一个文件夹:文件夹路径将类似\uploads \Year \Month \thumb - 月份和年份将每月和每年更改..... 编辑: 在浏览器的浏览器中,它给出了一个不同的路径:此行在此使用:< img runat =serversrc =''<%= 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 = 观看 align = left style = height:120px; width:150px; margin-bottom:10px; margin-left:32px; margin-right:15px; /> < / a > 此行:< img runat =server ImageUrl =''<%#Eval(ThumbPath)%>''/>给我正确的路径存储在db .... 解决方案 搜索Maincontent lvlist CTRL1 I''ve got a listview, which holds a bitmap (imagebutton) and details of the video. When I load the page this list should populate. All the details of the video clip populates, but no image is displayed. I store the images and videos in a folder, and the path of the images in a sql database. How do populate the image in the imagebutton? This is what Ive done:<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 ='<%= ResolveClientUrl(Eval("ThumbPath"))%>' CommandArgument='<%= ResolveClientUrl(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(); }The path will change from month to month.. the only part that will stay the same is uploads and the last folder: the folder path will be like \uploads\Year\Month\thumb - month and year will change every month and every year.....EDIT:In my view source on the browser it gives it gives me a different path: This line is used here: <img runat="server" src=''<%= 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>This line : <img runat="server" ImageUrl=''<%#Eval("ThumbPath") %>'' /> gives me the correct path which is stored in db.... 解决方案 MainContentlvlistctrl1 这篇关于使用数据库中的路径填充列表视图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 14:34