프로젝트
ico 폴더안에 있는 이미지를 가지고 와서 페이지에 뿌려준다
코드는 간단하니깐 설명은 패쓰~
aspx 소스
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function SelectImage(img) {
document.getElementById("userView").innerHTML = "<img src='/ico/" + img+"'>";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<strong>폴더에서 이미지를 읽어와서 리스트 뿌려주는부분<br />
</strong><br />
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<img src='/ico/<%# GetFileName( (string)Container.DataItem ) %>' style="height: 60px;
width: 64px" />
<input id="Button2" type="button" value="이미지 선택" onclick="SelectImage('<%# GetFileName( (string)Container.DataItem ) %>')" />
</ItemTemplate>
</asp:DataList>
</div>
</form>
<p>
<strong>클릭후 나타나는 부분</strong></p>
<hr />
<p>
선택한 이미지 >>><span id="userView"></span></p>
<p>
</p>
</body>
</html>
CS 코드
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//실제물리적 경로를 가지고 옵니다. //C:\Users\kojaedoo\Documents\Visual Studio 2010\WebSites\WebSite1\ico
string url = Server.MapPath("./ico");
//파일 목록을 가지고 옵니다.
string[] filelist = Directory.GetFiles(url);
//
this.DataList1.DataSource = filelist;
DataList1.DataBind();
}
}
//Default.aspx 에서 풀네임 경로에서 파일 이름만 가지고 옵니다.
//C:\Users\kojaedoo\Documents\Visual Studio 2010\WebSites\WebSite1\ico\untitled-1_hun0026.jpg 에서
//untitled-1_hun0026.jpg 만 추출한다.
public string GetFileName(string fullFileName)
{
return Path.GetFileName(fullFileName);
}
}
구현된 모습
'ASP.NET AJAX' 카테고리의 다른 글
| Javascript로 포스트백 발생시키기 (비하인드 메소드 호출) (0) | 2014.02.17 |
|---|---|
| 디자이너를 위한 asp.net 페이지 만들기 (0) | 2011.06.14 |
| [URL 맵핑/블로그 주소 / 단축주소] Routing in ASP.NET (0) | 2010.11.02 |
| 배열을 DataList에 바인딩하기 (0) | 2010.10.01 |
| [ GridView ] DataKeys , RowDataBound (데이터바인딩)간단한 사용법 (0) | 2010.06.01 |
| [ GridView,그리드뷰 ]페이징(page) 디자인 꾸미기 (0) | 2010.06.01 |
| [ FilterExpression,FilterParameters , 다중검색 ] 두개이상 검색할때... (0) | 2010.06.01 |
| [마스터 페이지, masterpage] 에서 유저컨트롤 안에 접근하기 (0) | 2010.06.01 |
| [마스터페이지 , masterpage ] PreviousPage 마스터페이지 컨트롤러에 접근 (0) | 2010.06.01 |
| [암호화,MD5,SHA1] 비밀번호 암호화 하기 (0) | 2010.06.01 |