日期:2014-05-17  浏览次数:20415 次

动态加载主题 dropdownlist控件 代码不懂
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  {
  string url = Request.Path + "?theme=" + DropDownList1.SelectedItem.Value;为什么这里要加Request.Path ?
  Response.Redirect(url);
  }
  void Page_Prelnit(object sender, EventArgs e) Page_Prelnit这个事件是什么意思?
  {
  string theme = "Theme1";
  if (Request.QueryString["theme"] == null)
  {
  theme = "Theme1";
  }
  else
  {
  theme = Request.QueryString["theme"];
  }
  Page.Theme = theme;
  ListItem item = DropDownList1.Items.FindByValue(theme);
if (item != null)
{
item.Selected = true;
}
这段代码什么意思,有什么作用?  
  }

 <asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true"
Height="16px" Width="150px">
<asp:ListItem Value="Theme1">主题1</asp:ListItem>
<asp:ListItem Value="Theme2">主题2</asp:ListItem>
</asp:DropDownList>
  上面的OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true" 什么意思?

------解决方案--------------------
string url = Request.Path + "?theme=" + DropDownList1.SelectedItem.Value;为什么这里要加Request.Path ?

Request.Path是页面的完整URL,防止出错

void Page_Prelnit(object sender, EventArgs e) Page_Prelnit这个事件是什么意思?

页面预初始化
参见
http://msdn.microsoft.com/zh-cn/library/system.web.ui.page.preinit%28v=vs.90%29.aspx

 ListItem item = DropDownList1.Items.FindByValue(theme);
if (item != null)
{
item.Selected = true;
}
这段代码什么意思,有什么作用?

根据theme的值,设置DropDownList1的默认选中项为theme的值


上面的OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true" 什么意思?

在改变DropDownList1的选项时,触发事件OnSelectedIndexChanged
------解决方案--------------------
Request.Path当前请求的虚拟路径
Page_Prelnit页面初始化
这些东西,自己翻翻帮助或msdn都有