0
      <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs"  Inherits="test"%>

      <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

       <!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>
      </head>
      <body style="height: 162px">
<form id="form1" runat="server">
<div>

    <asp:RadioButton ID="MCA" runat="server" Text="MCA" AutoPostBack="True" 
        oncheckedchanged="MCA_CheckedChanged" />
    <br />

</div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
    <asp:ListItem Value="Sem1"></asp:ListItem>
    <asp:ListItem Value="Sem2"></asp:ListItem>
</asp:DropDownList>
<br />
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" 
    onselectedindexchanged="DropDownList2_SelectedIndexChanged" 
    ViewStateMode="Enabled">
    <asp:ListItem Value="MCA101"></asp:ListItem>
    <asp:ListItem Value="MCA103">MCA103</asp:ListItem>
</asp:DropDownList>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
     <br />
        <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" 
            OnUploadComplete="upload"/>
    <br />
    </ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

イベントコード..

      protected void upload(Object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
      {
        string s = DropDownList1.SelectedValue;
        string t = DropDownList2.SelectedValue;
        string path= string path = Server.MapPath("~/MCA/" + s + "/" +t+ "/")+e.FileName 
      }

// s と t の両方が Dropdownlist の最初の値を取得します。他の値が選択されていて、そのアップロードがディレクトリ構造に従って行われていない場合でも同様です。

どちらの Dropdownlist にもいくつかの値があり、postbackプロパティは両方のリストで true です。

list の正確な選択値を取得するには?

4

2 に答える 2

0

問題はRequest.Form["__VIEWSTATE"] = null、AjaxFileUpload OnUploadComplete イベントが呼び出されたときです。

この問題の修正(C# コード):

ページの読み込み時にセッションでドロップダウンの選択を設定します。

protected void Page_Load(object sender, EventArgs e)
{
 if (Request.Form["__VIEWSTATE"] != null)
    Session["Path"] = "//" + DropDownList1.SelectedValue + "//" + DropDownList2.SelectedValue + "//";
}

ファイルパスの作成にセッション値を使用:

protected void upload(Object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
        string path = string.Empty;
        if (Session["Path"] != null)
            path = Server.MapPath("~//MCA" + (string)Session["Path"]) + e.FileName;
}
于 2013-03-26T10:52:03.573 に答える
0

アップロード コントロールと同じ更新パネルにドロップダウン リストを追加する必要があると思います。

于 2013-03-26T13:16:10.717 に答える