As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center作为指导。
6年前关闭。
根据asp.net中的下拉列表选择选项从文件夹动态加载多个图像。
有人可以帮助我在Visual Studio中实现吗?
这是我尝试的代码,可以为我提供更好的选择或进行修改,我还需要将图像输出以幻灯片方式绑定到图像按钮控件。
在幻灯片扩展器中
终于在page_load中
6年前关闭。
根据asp.net中的下拉列表选择选项从文件夹动态加载多个图像。
有人可以帮助我在Visual Studio中实现吗?
这是我尝试的代码,可以为我提供更好的选择或进行修改,我还需要将图像输出以幻灯片方式绑定到图像按钮控件。
<script type="text/javascript">
function new1(city) {
switch (city) {
case "Patna":
var imlocation = "Patna/";
var currentdate = 0;
var image_number = 0;
function ImageArray(n) {
this.length = n;
for (var i = 1; i <= n; i++) {
this[i] = ' '
}
}
image = new ImageArray(2)
image[0] = '2.jpg'
image[1] = '3.jpg'
var rand = 60 / image.length
function randomimage() {
currentdate = new Date()
image_number = currentdate.getSeconds()
image_number = Math.floor(image_number / rand)
return (image[image_number])
}
document.write("<img src='" + imlocation + randomimage() + "'>");
case "Bhopal":
var imlocation1 = "Bhopal/";
var currentdate1 = 0;
var image_number1 = 0;
function ImageArray1(n) {
this.length = n;
for (var i = 1; i <= n; i++) {
this[i] = ' '
}
}
image1 = new ImageArray1(3)
image1[0] = '2.jpg'
image1[1] = '4.jpg'
image1[2] = '1.jpg'
var rand1 = 100/ image1.length
function randomimage1() {
currentdate1 = new Date()
image_number1 = currentdate1.getSeconds()
image_number1 = Math.floor(image_number1 / rand1)
return (image1[image_number1])
}
document.write("<img src='" + imlocation1 + randomimage1() + "'>");
}
}
<asp:DropDownList ID="DropDownList1" runat="server" onchange="new1(this.value)"
DataSourceID="SqlDataSource1" DataTextField="City" DataValueField="City"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True" >
</asp:DropDownList>
最佳答案
最终,我自己找到了答案,使用ajax幻灯片扩展程序在webservice中使用以下代码。
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod]
public AjaxControlToolkit.Slide[] GetSlides(string contextKey)
{
string[] imagenames = System.IO.Directory.GetFiles(HttpContext.Current.Server.MapPath("~/" + contextKey ));
AjaxControlToolkit.Slide[] photos = new AjaxControlToolkit.Slide[imagenames.Length];
for (int i = 0; i < imagenames.Length; i++)
{
string[] file = imagenames[i].Split('\\');
photos[i] = new AjaxControlToolkit.Slide(contextKey + "/" + file[file.Length - 1], file[file.Length - 1], "");
}
return photos;
}
}
在幻灯片扩展器中
<asp:SlideShowExtender ID="SlideShowExtender1" TargetControlID="Image1" SlideShowServiceMethod="GetSlides" SlideShowServicePath="~/WebService1.asmx" Loop="true" runat="server" UseContextKey="true"
AutoPlay="True" BehaviorID="b1" >
</asp:SlideShowExtender>
终于在page_load中
if (Page.IsPostBack)
{
SlideShowExtender1.ContextKey = DropDownList1.SelectedValue;
}