[英]DropDownList refresh on second attempt in gridview asp.net c#
I am facing a problem while adding new records by selecting drop down items. 通过选择下拉菜单添加新记录时,我遇到了问题。 Basically it is a gridview in which I select AddressType, Country then City then CityArea and so on using dropdown.
基本上是一个gridview,在其中我选择AddressType,Country,City,CityArea,等等,使用下拉菜单。 In first attempt it is working fine, but on second attempt when I select Country it reset the selected item.
在第一次尝试中,它工作正常,但是在第二次尝试中,当我选择“国家/地区”时,它将重置所选项目。
http://i.stack.imgur.com/GoTtU.jpg http://i.stack.imgur.com/GoTtU.jpg
as you can see in the above picture, on second attempt I am going to select Country. 如您在上图中所看到的,在第二次尝试中,我将选择“国家/地区”。 As soon as I select the Country it refresh.
一旦选择“国家/地区”,它就会刷新。 Look in the below picture:
看下图:
http://i.stack.imgur.com/ObeT5.jpg http://i.stack.imgur.com/ObeT5.jpg
Please help me to find the solution. 请帮助我找到解决方案。 Thanks.
谢谢。
Here is my code: 这是我的代码:
<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#: C#:
protected void ddlCountryNew_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlCountryNew = (DropDownList)sender;
hdnCountryId.Value = ddlCountryNew.SelectedItem.Value;
}
If you want the dropdownlist to trigger Ajax call without refreshing the page 如果您希望下拉列表在不刷新页面的情况下触发Ajax调用
Set EventName="SelectedIndexChanged"
like below 如下所示设置
EventName="SelectedIndexChanged"
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlCountryNew" EventName="SelectedIndexChanged" />
</Triggers>
Have a keen look over through the Update Panel MSDN document with example 仔细浏览“ 更新面板” MSDN文档中的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.