C# asp.NET C(4.5)中非asp选择列表上的SelectValue

C# asp.NET C(4.5)中非asp选择列表上的SelectValue,c#,asp.net,query-string,C#,Asp.net,Query String,我有以下html代码index.aspx: <select class="ct-input ct-term" name="term"> <option value="5">5</option> <option value="10">10</option> </select> 我想从页面加载事件的代码隐藏中选择与querystring相关的选择列表的适当项。可能吗?Querystring看起来像:index.as

我有以下html代码index.aspx:

<select class="ct-input ct-term" name="term">
   <option value="5">5</option>
   <option value="10">10</option>
</select>
我想从页面加载事件的代码隐藏中选择与querystring相关的选择列表的适当项。可能吗?Querystring看起来像:index.aspx?term=10,所以选择值为10的选项

我在数字输入方面也有同样的问题,但这很简单,我所要做的就是让它运行在=server,然后写name.Value=something


不幸的是,这在这里不起作用,因为我的表单没有attr runat=server,我不想添加它,因为这样它也会添加一个viewstate,使url无法读取。还有其他解决办法吗?注:表单的方法必须是GET。

您可以在操作中以及根据ViewBag中的值选择的视图集中,将正确的项目设置到ViewBag中。例如:

public ActionResult (int term){
ViewBag.Term=term;
return View();
}

<select class="ct-input ct-term" name="term">
   <option value="5" <% if(ViewBag.Term==5){<text>selected</text>} %> >5</option>
   <option value="10" <% if(ViewBag.Term==10){<text>selected</text>} %> >10</option>
</select>

如果不愿意使用服务器端控件进行处理,则必须使用Javascript/JQuery。对于这种简单的情况,您对ViewState的关注似乎有点误导,或许您可以阅读一下