一、AutoPostBack刷新页面

DropDownList使用AutoPostBack常遇见两个问题:

DropDownList点击不触发事件

需要加上AutoPostBack=<font style="color:rgb(128, 0, 0);">"true"</font>这个属性

加入AutoPostBack后全局刷新

asp中使用UpdatePanel
  1. <asp:ScriptManager ID="ScriptManager1" runat="server">
  2. </asp:ScriptManager>
  3. <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
  4. <ContentTemplate>
  5. <asp:DropDownList ID="ddlcountry" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlcountry_SelectedIndexChanged">
  6. </asp:DropDownList>
  7. </ContentTemplate>
  8. </asp:UpdatePanel>
  1. <asp:UpdatePanel ID="UpdatePanel2" runat="server">
  2. <ContentTemplate>
  3. <asp:DropDownList ID="ddpostway" runat="server">
  4. </asp:DropDownList>
  5. </ContentTemplate>
  6. </asp:UpdatePanel>

具体:

  1. 哪里使用了AutoPostBack哪里加入UpdatePanel
  2. 哪里需要联动更新的使用UpdatePanel

二、onchange事件

  1. functionselectDpList(dp) {
  2. varsIndex=dp.selectedIndex;//返回选中是第几项 0,1....
  3. varsText=dp.options[dp.selectedIndex].text;//返回选中的文本--文本1,文本2 ...
  4. varsValue=dp.value;//返回选中的文本--v1,v2 ...
  5. }
  1. <asp:DropDownListrunat="server"CssClass="productType"ID="dp_ProductTag"Width="153px"onchange="JavaScript:selectDpList(this)">
  2. <asp:ListItemText="文本1"Value="1"></asp:ListItem>
  3. <asp:ListItemText="文本2"Value="2"></asp:ListItem>
  4. <asp:ListItemText="文本3"Value="2"></asp:ListItem>
  5. </asp:DropDownList>

若有收获,就点个赞吧