下拉列表事件

时间:2011-10-21 10:05:13

标签: asp.net vb.net

我有一个网络表单,其中我已经下载了6个下拉列表,每个下拉列表都有前七个日期来打开文件名称末尾的日期连接的特定文件夹中的文件。问题是,当我选择第一个下拉列表时,它打开文件很好,但是当我从任何其他下拉列表中选择一个日期来打开文件时,它会打开从第一个下拉列表中打开的相同文件。请查看代码并在其中进行更正。

我的代码是Bellow

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
Imports System.Data.SqlClient
Imports System.Diagnostics.Process
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Console
Partial Class DashBoard
    Inherits System.Web.UI.Page
    Protected Sub DD1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD1.SelectedIndexChanged
        Response.Redirect("Reports/Daily Production and Stock Report (Crescent Ujala)/Daily Production and Stock Report (Crescent Ujala) " & DD1.SelectedValue & ".xls")
    End Sub
    Protected Sub DD2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD2.SelectedIndexChanged
        Response.Redirect("Reports/Daily Production Efficiency Report (Crescent Ujala)/Daily Production Efficiency Report (Crescent Ujala) " & DD2.SelectedItem.Value.ToString & ".pdf")
    End Sub
    Protected Sub DD3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD3.SelectedIndexChanged
        Response.Redirect("Reports/September Sowing Report/September Sowing Report " & DD3.SelectedItem.Value.ToString & ".ods")
    End Sub
    Protected Sub DD4_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD4.SelectedIndexChanged
        Response.Redirect("Reports/September Sowing Report Area-1/September Sowing Report Area-1 " & DD4.SelectedItem.Value.ToString & ".ods")
    End Sub
    Protected Sub DD5_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dd5.SelectedIndexChanged
        Response.Redirect("Reports/September Sowing Report Area-2/September Sowing Report Area-2 " & dd5.SelectedItem.Value.ToString & ".ods")
    End Sub
    Protected Sub DD6_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD6.SelectedIndexChanged
        Response.Redirect("Reports/Daily P & L Cost sheet/Daily P & L Cost sheet. " & DD6.SelectedValue & ".xls")
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Add Values to Dropdownlist 1
        DD1.Items.Add(New ListItem("", ""))
        DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
        DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
        DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
        DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
        DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
        DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
        DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
        'Add Values to Dropdownlist 2

        DD2.Items.Add(New ListItem("", ""))
        DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
        DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
        DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
        DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
        DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
        DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
        DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
        'Add Values to Dropdownlist 3

        DD3.Items.Add(New ListItem("", ""))
        DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
        DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
        DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
        DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
        DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
        DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
        DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
        'Add Values to Dropdownlist 4

        DD4.Items.Add(New ListItem("", ""))
        DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
        DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
        DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
        DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
        DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
        DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
        DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
        'Add Values to Dropdownlist 5

        dd5.Items.Add(New ListItem("", ""))
        dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
        dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
        dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
        dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
        dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
        dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
        dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
        'Add Values to Dropdownlist 6
        DD6.Items.Add(New ListItem("", ""))
        DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
        DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
        DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
        DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
        DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
        DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
        DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))


    End Sub
End Class

2 个答案:

答案 0 :(得分:0)

您是否检查过以确保其他下拉列表的OnChange事件引用了代码中的正确方法?他们可能都引用了DD1_SelectedIndexChanged

顺便说一下,你真的应该考虑重构一些代码,因为你有重复的批次。列表填充代码也应该真正移入On_Init事件。

答案 1 :(得分:0)

将DropdownList的绑定逻辑放在IsPostaback中,如下所示

如果不是page.ispostback

//然后绑定

结束如果