<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Top.aspx.cs" Inherits="Top" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>页眉</title>
    <style type="text/css">
        .style1
        {
            text-align: right;
            height: 150px;
        }
        .style2
        {
            font-size: xx-large;
        }
        .style3
        {
            width: 100%;
        }
        .style4
        {
            height: 84px;
            text-align: center;
            font-size: xx-large;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style1">
        <span class="style2"></span>
        <table class="style3">
            <tr>
                <td class="style4">
                            文件管理</td>
            </tr>
            <tr>
                <td>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="上传" 
            Width="80px" />
        <asp:FileUpload ID="FileUpload1" runat="server" Width="176px" />
                    <asp:DropDownList ID="DropDownList1" runat="server" Height="16px" 
                                Width="84px">
                                <asp:ListItem Value="ppt/">初一级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">初一级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">初二级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">初二级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">初三级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">初三级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">高一级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">高一级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">高二级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">高二级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">高三级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">高三级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">通知ppt</asp:ListItem>
                                <asp:ListItem Value="word/">通知word</asp:ListItem>
                            </asp:DropDownList>
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="下载" 
            Width="80px" />
        <asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="删除" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;public partial class Top : System.Web.UI.Page
{
    string downpath = "";
    string mpath="";
    protected void Page_Load(object sender, EventArgs e)
    {
            if (Session["dlm"].ToString() == "admin")
            {
                Button3.Enabled = true;
            }
            else
                Button3.Enabled = false;
            if (!IsPostBack)
            {
                select();
            }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //if (Session["dlm"].ToString() != "")
        //{
            string filePath = "", fileExtName = "", mFileName;
            if ("" != FileUpload1.PostedFile.FileName)
            {
                select();
                filePath = FileUpload1.PostedFile.FileName;
                fileExtName = filePath.Substring(filePath.LastIndexOf(".") + 1);
                if (fileExtName == "doc" || fileExtName == "ppt")
                {
                    try
                    {
                        mFileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                        FileUpload1.PostedFile.SaveAs(mpath+"\\"+DropDownList1.SelectedValue+mFileName);
                        Response.Write("<script language =javascript>alert('上传成功');history.back();</script>");
                    }
                    catch (Exception error)
                    {
                        Response.Write("<script language =javascript>alert('" + error.ToString() + "')</script>");
                    }
                }
                else
                {
                    Response.Write("<script language =javascript>alert('文件格式不对');history.back();</script>");
                    return;
                }
            }
            else
            {
                Response.Write("<script language =javascript>alert('请选择文件');history.back();</script>");
            }
        //}
        //else
        //{
        //    Response.Write("<script language =javascript>alert('请先登陆');history.back();</script>");
        //    return;
        //}
    }
    public void select()
    {
        switch (DropDownList1.SelectedItem.Text)
        {
            case "初一级ppt":
                mpath = Server.MapPath("初一级");
                break;
            case "初一级word":
                mpath = Server.MapPath("初一级");
                break;
            case "初二级ppt":
                mpath = Server.MapPath("初二级");
                break;
            case "初二级word":
                mpath = Server.MapPath("初二级");
                break;
            case "初三级ppt":
                mpath = Server.MapPath("初三级");
                break;
            case "初三级word":
                mpath = Server.MapPath("初三级");
                break;
            case "高一级ppt":
                mpath = Server.MapPath("高一级");
                break;
            case "高一级word":
                mpath = Server.MapPath("高一级");
                break;
            case "高二级ppt":
                mpath = Server.MapPath("高二级");
                break;
            case "高二级word":
                mpath = Server.MapPath("高二级");
                break;
            case "高三级ppt":
                mpath = Server.MapPath("高三级");
                break;
            case "高三级word":
                mpath = Server.MapPath("高三级");
                break;
            case "通知ppt":
                mpath = Server.MapPath("通知");
                break;
            case "通知word":
                mpath = Server.MapPath("通知");
                break;
        }
    }

解决方案 »

  1.   

    protected void Page_Load(object sender, EventArgs e)
      {
    这里面包含的代码加上if(!IsPostBack)
      

  2.   

    protected void Page_Load(object sender, EventArgs e)
      {
     if (!IsPostBack)
      {
      select();
      }
      if (Session["dlm"].ToString() == "admin")
      {
      Button3.Enabled = true;
      }
      else
      Button3.Enabled = false;
     
      }
      

  3.   

    估计就是楼上说的那样的,你要考虑两个,一个是页面回传的问题就是加!ispostBack,还有就是在加载事件里调用了,但是你重新选中了DropDownList1的项后没有确定它的值,当然每次就是第一项的值
      

  4.   

    你开启DropDownList1的autopostback属性才行,在它的选择事件里加代码就好了
      

  5.   

    if(!ispostback)
    {
    bindddlst();
    }
      

  6.   

    DropDownList的AutoPostBack属性没有设置
      

  7.   

    protected void Page_Load(object sender, EventArgs e)
      {
       if(!IsPostBack)
      {
       select();
      }
      Button3.Enabled =Session["dlm"].ToString() == "admin"? true:false;
     
     }
      

  8.   

    都不行啊  如果设置AutoPostBack属性  所选的值会消失  一选它就还原成默认值了
      

  9.   

     if (!IsPostBack)
      {
      select();// 这里是要放置初始化DropDownList1的数据的,但数据我已经事先写在里面了,<asp:ListItem Value="ppt/">初一级ppt</asp:ListItem>
    我设AutoPostBack=true,时所选的值立即刷新  变成初始化了,所以变成总是第一项,但是不知道怎么解决这的问题
      }
      

  10.   

    pageload 里面加个POSTBACK 判断啊
      

  11.   

    pageload 里面加个POSTBACK 判断啊  我已经判断过了  但是判断的内容我觉得是不正确的,如if (!IsPostBack)
      {
      select();
      }
    不知道怎么该啊 麻烦高手们解决一下!!
      

  12.   


    <asp:ListItem Value="ppt/">初一级ppt</asp:ListItem>
      <asp:ListItem Value="word/">初一级word</asp:ListItem>
      <asp:ListItem Value="ppt/">初二级ppt</asp:ListItem>
      <asp:ListItem Value="word/">初二级word</asp:ListItem>
      <asp:ListItem Value="ppt/">初三级ppt</asp:ListItem>
      <asp:ListItem Value="word/">初三级word</asp:ListItem>
      <asp:ListItem Value="ppt/">高一级ppt</asp:ListItem>
      <asp:ListItem Value="word/">高一级word</asp:ListItem>
      <asp:ListItem Value="ppt/">高二级ppt</asp:ListItem>
      <asp:ListItem Value="word/">高二级word</asp:ListItem>
      <asp:ListItem Value="ppt/">高三级ppt</asp:ListItem>
      <asp:ListItem Value="word/">高三级word</asp:ListItem>
      <asp:ListItem Value="ppt/">通知ppt</asp:ListItem>
      <asp:ListItem Value="word/">通知word</asp:ListItem>
    必须保证每个value都唯一,否则就会出现你这种莫名其妙的问题
      

  13.   

    非常感谢bearben2010  真是这个问题