【发布时间】:2020-08-12 11:52:25
【问题描述】:
亲爱的,我有以下下拉列表,它位于中继器内的更新面板内。
<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()
当我选择一个值时,下拉列表会重置为下拉列表中的第一项,而不是保留所选值。
我想保留那个价值。
谢谢。
【问题讨论】: