목록 상자와 이미지 상자를 둡니다. 이제 사용자가 목록의 다른 요소를 클릭 할 때마다 이미지를 교환하고 싶습니다. 사물의ASP. 목록 및 그림
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
string[] pictures = { "~/createWii.jpg",
"~/DKC4_wii.png",
"~/Donkey-Kong-Country-1.jpg",
"~/DSCallOfDutyBlackOps.jpg",
"~/DSPreviewsCodmw2.jpg",
"~/DSPreviewsAliceInWonderLAnds.jpg",
"~/DSPreviewPicross3d.jpg",
"~/createii.jpg",
};
string[] picturesNames = { "picture1", "picture2", "picture3", "picture4", "picture5", "picture6", "picture7", "picture8" };
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < pictures.Length; i++)
{
ListBox1.Items.Add(new ListItem(picturesNames[i],pictures[i]));
}
Image1.ImageUrl = "~/Donkey-Kong-Country-1.jpg";
ListBox1.DataSource = picturesNames;
ListBox1.DataBind();
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Image1.ImageUrl = pictures[ListBox1.SelectedIndex];// it tells me that there is index out of range each time. why ?
}
}
이 질문에 대해서는 클라이언트 쪽 코드를 사용하는 것이 좋습니다. 실제로 이미지를 스왑하는 데는 전체 포스트 백이 필요하지 않습니다. 구글은 "jQuery 이미지 슬라이더"에 대한 자세한 내용을 볼 수 있습니다. –