Request.Form[4]的疑问?
看到个代码,显示页面中用了个DropDownList,列了些下拉选项.用来选择皮肤
在cs中用个 Session[ "Theme "] = this.Request.Form[4].Trim();
我不明白为什么Form[4]就能取到那些选值呢?
Form是取请求中表单值,那个人能说下Request.Form怎么用,给个连接我自己看也行,谢谢了!
上面问题aspx的代码
请选择皮肤: <asp:DropDownList
id= "dropTheme "
AutoPostBack= "true "
Runat= "Server " >
<asp:ListItem Text= "Aqua " />
<asp:ListItem Text= "Black " />
<asp:ListItem Text= "Fuschia " />
<asp:ListItem Text= "Green " />
<asp:ListItem Text= "Khaki " />
<asp:ListItem Text= "Lavender " />
<asp:ListItem Text= "Lemon " />
<asp:ListItem Text= "Peach " />
<asp:ListItem Text= "Red " />
<asp:ListItem Text= "White " Selected= "True " />
</asp:DropDownList>
cs的代码
public void Page_PreInit()
{
if (Request.Form != null && Request.Form.Count > 0)
Session[ "Theme "] = this.Request.Form[4].Trim();
else
if (Session[ "Theme "] == null)
Session[ "Theme "] = "White ";
this.Theme = (string)(Session[ "Theme "]);
}
protected void Page_Load(object sender, EventArgs e)
{
foreach (ListItem li in dropTheme.Items)
{
if (li.Value.ToString() == (string)(Session[ "Theme "]))
li.Selected = true;