如何解决回发后转发器更新面板中的下拉列表丢失值
亲爱的我在中继器的更新面板中有以下下拉列表。
<asp:Repeater OnItemDataBound="rprProperties_ItemDataBound" ID="rprProperties" runat="server">
<ItemTemplate>
<div class="mb-2">
<asp:Label style="width : 100px;float:left;" ID="Label1" runat="server" Text='<%# Container.DataItem("name") %>'></asp:Label>
<asp:Label style="width : 100px;float:left;" ID="propID" runat="server" Text='<%# Container.DataItem("id") %>' Visible="false"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ClientIDMode="AutoID" AutoPostBack="true" OnSelectedIndexChanged="ddlProperty_SelectedIndexChanged" style="width:100px" CssClass="filter-dropdown bg-light" DataValueField="id" DataTextField="name" ID='ddlProperty' runat="server"></asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ItemTemplate>
</asp:Repeater>
我在转发器的ItemDataBound事件中用此代码填充ddl。
Dim propID As Label = TryCast(e.Item.FindControl("propID"),Label)
Dim ddl As DropDownList = TryCast(e.Item.FindControl("ddlProperty"),DropDownList)
Dim varDbconn As New SqlConnection(ConfigurationManager.ConnectionStrings("shopCS").ToString)
Dim varDbcomm As SqlCommand
Dim varDbRead As SqlDataReader
varDbconn.Open()
varDbcomm = New SqlCommand("exec spShowItemPropValues @property,@id,@lang ",varDbconn)
varDbcomm.Parameters.AddWithValue("@property",SqlDbType.Int).Value = propID.Text
varDbcomm.Parameters.AddWithValue("@id",SqlDbType.Int).Value = Request.QueryString("id")
varDbcomm.Parameters.AddWithValue("@lang",SqlDbType.NVarChar).Value = Session("lang")
varDbRead = varDbcomm.ExecuteReader()
Dim varDt As New DataTable
varDt.Load(varDbRead)
ddl.DataSource = varDt
ddl.DataBind()
varDbcomm.Dispose()
varDbRead.Close()
varDbconn.Close()
当我选择一个值时,下拉列表将重置为下拉列表中的第一项,而不是保留所选值。
我想保留那个值。
谢谢。
解决方法
您忘记添加AsyncPostBackTrigger。将其放在</UpdatePanel>
<asp:Repeater OnItemDataBound="rprProperties_ItemDataBound" ID="rprProperties" runat="server">
<ItemTemplate>
<div class="mb-2">
<asp:Label style="width : 100px;float:left;" ID="Label1" runat="server" Text='<%# Container.DataItem("name") %>'></asp:Label>
<asp:Label style="width : 100px;float:left;" ID="propID" runat="server" Text='<%# Container.DataItem("id") %>' Visible="false"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ClientIDMode="AutoID" AutoPostBack="true" OnSelectedIndexChanged="ddlProperty_SelectedIndexChanged" style="width:100px" CssClass="filter-dropdown bg-light" DataValueField="id" DataTextField="name" ID='ddlProperty' runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProperty" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
</ItemTemplate>
</asp:Repeater>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。