我目前正在尝试创建一个用户选择月份的下拉列表.droplist本身可以工作,但每当我尝试获取它的值时,它就会失败.我认为最简单的解释方法是显示我的代码和错误信息,因为我不确定我会怎么做.
错误信息:
CS0019:运算符'=='不能应用于'char'和'string'类型的操作数
带下拉列表的HTML:
<h4 class="monthYear">
<form action="WebForm1.aspx" method="get">
<select name="monthList">
<option class="month">Januari</option>
<option class="month">Februari</option>
<option class="month">Mars</option>
<option class="month">Maj</option>
<option class="month">Juli</option>
<option class="month">Juni</option>
<option class="month">Augusti</option>
<option class="month">Oktober</option>
<option class="month">September</option>
<option class="month">November</option>
<option class="month">December</option>
</select>
<input type="submit" name="setMonth" value="Visa" />
</form>
</h4>
Run Code Online (Sandbox Code Playgroud)
C#代码,我试图从列表中获取他们选择的任何内容:
<%
var Januari = Request["Januari"];
var Februari = Request["Februari"];
var monthList = Request["monthList"];
foreach (var month in monthList)
{
if (month == "Januari") <-- This == is what it doesn't seem to like.
{
Response.Write("Working");
var setYear = 2015;
var setMonth = 1;
}
}
%>
Run Code Online (Sandbox Code Playgroud)
monthList是一个string,通过做一个foreach,你得到了char.
我想你想分开monthList一些东西,;也许是:
foreach (var month in monthList.Split(';'))
{ }
Run Code Online (Sandbox Code Playgroud)
现在,month是一个string.
如果返回的值不是任何列表,您可能只想放弃它foreach.
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |