DropdownList 服务器取不到值问题

Sizy 2018-02-12 11:00:40
如题,下拉控件在本地正常获取值。放到服务器上就取不到值了,点了下拉没一点东西。有劳各位大神帮助在下看一下,是什么情况,代码如下
前台:

function toFile(fileName, zhiId, zhiling) {
var a = document.createElement("a");
a.href = "zhir.aspx?fileName=" + fileName;
document.body.appendChild(a);
a.click();
}

前台有一个fileUpload 的取excel文件地址的控件,点击上传按钮根据获取的地址,找到excel文件并把他的sheet页都循环一遍,加入到下拉控件sheetname中
<asp:FileUpload ID="FileUpload1" runat="server" />
上传按钮
<asp:Button ID="Button1" runat="server" Text="上传" OnClick="Button1_Click" Style="height: 21px" />

<asp:DropDownList ID="Sheetname" runat="server" name="dId" Enabled="True"
Height="18px" Width="136px" AutoPostBack="true" EnableViewState="true">
</asp:DropDownList>

后台:
/// <summary>
///上传按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath("~/save/") + FileUpload1.FileName);
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>toFile('" + FileUpload1.FileName + "','" + this.hidenId.Value + "','" + this.Label2.Text + "');</script>");
}
}

//加载
if (!IsPostBack)
{
//带的参数
zhiId = Request.QueryString["zhiId"];
this.hidenId.Value = zhiId;
zhiling = Request.QueryString["zhiling"];
this.Label2.Text = zhiling;
fileName = Request.QueryString["fileName"];
this.Label3.Text = fileName;
}
if (fileName != null)
{
this.hidenFile.Value = fileName;
fileName = Server.MapPath("~/save/") + fileName;
//加载下拉
this.Sheetname.DataSource =[color=#33CCCC] GetExcelSheetNames[/color](fileName);
this.Sheetname.DataBind();
}

/// <summary>方法
/// 获得当前你选择的Excel Sheet的所有名字
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
private static List<string> GetExcelSheetNames(string filePath)
{

List<string> names = new List<string>();
Microsoft.Office.Interop.Excel.Application excelApp = null;
object missing = System.Reflection.Missing.Value;
try
{
excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbooks wbs = excelApp.Workbooks;
Microsoft.Office.Interop.Excel.Workbook wb = wbs.Open(filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
int count = wb.Worksheets.Count;
for (int i = 1; i <= count; i++)
names.Add(((Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[i]).Name);
wb.Close(missing, missing, missing);
wb = null;
excelApp.Quit();
}
catch (System.Exception ex)
{
excelApp.Quit();
//XException xe = FuncLib.BuildXExcpetion("获得当前你选择的Excel Sheet的所有名字出错", ex);
//xe.WriteLogRecord(false, true, DateTime.Now.ToString("yyyy-MM-dd"));
}
return names;
}
...全文
1202 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2018-02-23
  • 打赏
  • 举报
回复
去掉GetExcelSheetNames方法中的try...catch语句看报错了没有

Web开发学习资料推荐
配置chrome支持本地(file协议)ajax请求
jqGrid导航Navigator配置

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧