我有一个表单,我在其中放置了一个转发器控件并将其绑定到 pageLoad,它按预期绑定。
我有一个dropDownList
,当我从中选择一个值时,我想清除转发器数据dropDown_SelectedIndexChanged
源并在代码隐藏的事件处理程序中重新绑定它。
我将转发器数据源设置为空,然后用新的数据源重新绑定它,它不会反映更改,它显示第一个绑定值。
这是我的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
return;
//Populate the drop down
PopulateLocationDropdown();
if (Request.QueryString["locationID"] != null)
{
int locationID=Request.QueryString["locationID"];
//Clear repeater
rpt_Displaytheater.DataSource = null;
rpt_Displaytheater.DataBind();
//Rebind repeater
rpt_Displaytheater.DataSource = GetTheaterDataSet(locationID);
rpt_Displaytheater.DataBind();
}
}
当下拉selectionChanged:
protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
{
int locationID=ddlLocation.SelectedValue.ToInt();
//Clear repeater
rpt_Displaytheater.DataSource = null;
rpt_Displaytheater.DataBind();
//Rebind repeater
rpt_Displaytheater.DataSource = GetTheaterDataSet(locationID);
rpt_Displaytheater.DataBind();
}
编辑
这是我的下拉列表:
<asp:DropDownList ID="ddlLocation" DataTextField="LocationName" DataValueField="Record_Id" runat="server" CssClass="textbox_230"
OnSelectedIndexChanged="ddlLocation_SelectedIndexChanged" AutoPostBack="True">
</asp:DropDownList>
这是我的中继器:
<asp:Repeater ID="rpt_Displaytheater" runat="server"
OnItemCommand="rpt_Displaytheater_ItemCommand">
<ItemTemplate>
<div class="TheaterListing" style="background: #FFF;">
<div class="TheaterName">
<div class="Theaterhead">
<asp:Label ID="lblTheaterID" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "Record_Id") %>'></asp:Label>
<asp:LinkButton ID="lnkbtnTheaterName" runat="server" Style="color: #000; font-weight: bold" Text='<%# DataBinder.Eval(Container.DataItem, "Theatre_Name") %>'></asp:LinkButton>
</div>
</div>
<div class="showlist">
<%-- show time repeater-Movies Tab --%>
<asp:Repeater ID="rpt_showtime" runat="server">
<ItemTemplate>
<ul style="padding-left: 10px; margin: -18px 0 0 163px;">
<li class="fl" style="font-weight: bold; padding-left: 8px;">
<asp:LinkButton ID="lnk_showtime" CommandName="Showtime" runat="server" CssClass="txtstyle1"
Text='<%# DataBinder.Eval(Container.DataItem, "Time_From") %>'></asp:LinkButton>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
<%-- show time repeater-Movies Tab --%>
<%--<asp:LinkButton ID="LinkButton1" runat="server" style="color: #000;font-weight:bold" Text="10.00 AM"></asp:LinkButton>--%>
</div>
</div>
<br clear="all" />
</ItemTemplate>
</asp:Repeater>
我的问题是,当我在下拉选择更改时将转发器控件的数据源重置为新数据源但更改未反映在转发器上时,它只显示页面加载时的第一个有界值我的代码有什么问题