2015-07-11 19 views
0

我正在通過選擇下拉項目添加新記錄時遇到問題。基本上這是一個gridview,我選擇AddressType,國家然後城市CityArea等使用下拉菜單。在第一次嘗試中它工作正常,但在第二次嘗試時,我選擇國家它重置選定的項目。DropDownList刷新第二次嘗試在GridView asp.net c#

http://i.stack.imgur.com/GoTtU.jpg

,你可以在上面的圖片中看到,在第二次嘗試,我要選擇國家。只要我選擇國家它刷新。看看在下面的圖片:

http://i.stack.imgur.com/ObeT5.jpg

請幫我找到解決方案。 謝謝。

這裏是我的代碼:

<asp:TemplateField HeaderText="Country" HeaderStyle-Width="14%"> 
         <ItemTemplate> 
          <asp:Label ID="lblCountry" Text='<%# DataBinder.Eval(Container, "DataItem.Country.Description") %>' 
           runat="server"> </asp:Label> 
         </ItemTemplate> 
         <FooterTemplate> 
          <asp:UpdatePanel runat="server" ID="UPCountry"> 
          <ContentTemplate> 
           <asp:DropDownList ID="ddlCountryNew" DataSourceID="odsCountry" runat="server" OnSelectedIndexChanged="ddlCountryNew_SelectedIndexChanged" 
            AutoPostBack="true" DataTextField="Description" DataValueField="Id" CssClass="myWidth-7" /> 
          </ContentTemplate> 
          <Triggers> 
           <asp:AsyncPostBackTrigger ControlID="ddlCountryNew" /> 
          </Triggers> 
         </asp:UpdatePanel> 
         </FooterTemplate> 
         <EditItemTemplate> 
          <asp:DropDownList ID="ddlCountry" DataSourceID="odsCountry" runat="server" SelectedValue='<%# DataBinder.Eval(Container, "DataItem.CountryId") %>' 
           DataTextField="Description" DataValueField="Id" CssClass="myWidth-6" ValidationGroup="EditAddressGroup" /> 
         </EditItemTemplate> 
        </asp:TemplateField> 

C#:

protected void ddlCountryNew_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     DropDownList ddlCountryNew = (DropDownList)sender; 
     hdnCountryId.Value = ddlCountryNew.SelectedItem.Value; 
    } 

回答

0

如果你想在下拉列表觸發Ajax調用而無需刷新頁面

設置EventName="SelectedIndexChanged"像下面

<Triggers> 
<asp:AsyncPostBackTrigger ControlID="ddlCountryNew" EventName="SelectedIndexChanged" /> 
</Triggers> 

有一個敏銳的目光通過Update Panel MSDN document with example

+0

沒有..仍然有問題。 –

+0

你可以把你的整個代碼顯示到http://jsfiddle.net/並給 – BNN