如何使用上传者名称显示图像? [英] How to display image with the uploader name?

查看:83
本文介绍了如何使用上传者名称显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Web表单应用程序(VB.Net)创建一个网站,该网站要求用户在他们上传图片之前登录。上传的所有图像都将与上传者名称一起显示。我确信它使用会话来做但我不知道怎么做。



我尝试了什么:



这是我的Default.aspx用于显示图像:



I am creating a website using Web Form Application (VB.Net) that require user to login before they can upload their picture there. All images that uploaded will be displayed along with the uploader name. I am sure that it using the session to do it but I have no idea how.

What I have tried:

Here is my Default.aspx for displaying images :

<asp:DataList Width="100%" ID="imgDataList" runat="server" RepeatColumns="4" CellPadding="10">
	<ItemTemplate>
		<table  runat="server" id="tblImgList" border="1" width="100%">
			<tr>
				<td align="center">
					<a id="Link1"  runat="server" href='<%# Eval("Value") %>' target="Default.aspx">
						<asp:Image ID="imgDisp" ImageUrl='<%# Eval("Value") %>' runat="server" style="height :200px ; width :200px ;" />
					</a> 
				</td>
			</tr>
			<tr>
				<td align="center">
					<%# Eval("Text") %>
				</td>
			</tr>
		</table>
	</ItemTemplate>
</asp:DataList>





这是我的VB.Net代码,用于显示图片:





This is my VB.Net code to display the images :

If Not IsPostBack Then
            Dim filePaths As String() = Directory.GetFiles(Server.MapPath("~/Images/"))
            Dim files As New List(Of ListItem)()
            For Each filePath As String In filePaths
                Dim fileName As String = Path.GetFileName(filePath)
                files.Add(New ListItem(fileName, "~/Images/" + fileName))   'Automatically add pictures in listdata. Displayed using databind
            Next
            imgDataList.DataSource = files
            imgDataList.DataBind()
        End If





我想替换此代码



I want to replace this code

<%# Eval("Text") %>

并使用它来显示其上载名称而不是图像名称。

and use it to display the Uploader name there instead of the image name.

推荐答案

如果您对 Sessions 一无所知,请先阅读它。所以,首先需要检查会话是否存在。如果它存在,您将加载页面,否则重定向到登录或执行某些操作。



设计a登录页面,用户可以提供用户名密码登录。当用户单击登录时,您将这些凭据与数据库中存储的详细信息(在注册用户时插入)相匹配。如果匹配,您将重定向到主页或其他内容。



然后您可以在会话中存储用户的名字或任何您想要的内容,并在应用程序的任何位置使用它,甚至在那个 DataList
If you don't have an idea about Sessions, hen read it first. So, you first need to check if session is there or not. If it exists, you will load the page, else redirect to login or do some action.

Design a login page, where user can provide username and password to login. When user clicks on login, you match these credentials with the stored details in database (which is inserted while registering the user). If matched, you will redirect to a home page or something.

Then you can store the user's name or whatever you want in session and use it anywhere in the app, even on that DataList.


这篇关于如何使用上传者名称显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆