LinqDataSource“选择时”事件不会在回发时触发
我有一个带有两个下拉列表控件的网页,每个控件都绑定到单独的 LinqDataSource 对象。一个显示类别列表,另一个显示文章列表。类别选择驱动文章列表(至少,这是我的预期行为)。文章列表也会根据用户的语言首选项进行过滤,存储在会话中并应用在 ArticleLinqDataSource_Selecting
事件处理程序中。
<asp:Label runat="server" Text="Category Code:" AssociatedControlID="CategoryDropDownList" />
<asp:DropDownList runat="server" ID="CategoryDropDownList" DataSourceID="CategoryLinqDataSource" DataValueField="CategoryID" DataTextField="CategoryCode" AutoPostBack="true" />
...
<asp:Label runat="server" Text="Article Code:" AssociatedControlID="ArticleCodeDropDown" />
<asp:DropDownList runat="server" ID="ArticleCodeDropDown" DataSourceID="ArticleLinqDataSource" DataValueField="ArticleID" DataTextField="ArticleCode" OnDataBound="ArticleCodeDropDown_DataBound" />
...
<asp:LinqDataSource runat="server" ID="CategoryLinqDataSource"
ContextTypeName="Article.Data.ArticleDataContext"
TableName="Categories" Select="new (CategoryID, CategoryCode)">
</asp:LinqDataSource>
...
<asp:LinqDataSource runat="server" ID="ArticleLinqDataSource"
ContextTypeName="Arcicle.Data.ArticleDataContext"
TableName="Articles" OrderBy="ArticleCode"
Select="new (ArticleID, ArticleCode)"
OnSelecting="ArticleLinqDataSource_Selecting">
</asp:LinqDataSource>
当页面首次加载时,这一切都工作正常。类别列表包含所有可用的类别值,并且选择列表中的第一个类别。第一个类别的相应文章会适当地显示在文章下拉控件中。但是,当我更改类别时(会发生回发,因为我将其设置为 AutoPostBack="true"
),文章下拉列表不会刷新。换句话说,OnSelecting 事件不会刷新这是预期的行为吗?如果是,我该如何解决这个问题?
I have a web page with two dropdownlist controls, each bound to separate LinqDataSource objects. One displays a list of Categories and the other displays a list of Articles. The Category choice drives Article list (at least, that's my intended behaviour). The Article list is also filtered based on the users language preference, stored in the Session and applied in the ArticleLinqDataSource_Selecting
event handler.
<asp:Label runat="server" Text="Category Code:" AssociatedControlID="CategoryDropDownList" />
<asp:DropDownList runat="server" ID="CategoryDropDownList" DataSourceID="CategoryLinqDataSource" DataValueField="CategoryID" DataTextField="CategoryCode" AutoPostBack="true" />
...
<asp:Label runat="server" Text="Article Code:" AssociatedControlID="ArticleCodeDropDown" />
<asp:DropDownList runat="server" ID="ArticleCodeDropDown" DataSourceID="ArticleLinqDataSource" DataValueField="ArticleID" DataTextField="ArticleCode" OnDataBound="ArticleCodeDropDown_DataBound" />
...
<asp:LinqDataSource runat="server" ID="CategoryLinqDataSource"
ContextTypeName="Article.Data.ArticleDataContext"
TableName="Categories" Select="new (CategoryID, CategoryCode)">
</asp:LinqDataSource>
...
<asp:LinqDataSource runat="server" ID="ArticleLinqDataSource"
ContextTypeName="Arcicle.Data.ArticleDataContext"
TableName="Articles" OrderBy="ArticleCode"
Select="new (ArticleID, ArticleCode)"
OnSelecting="ArticleLinqDataSource_Selecting">
</asp:LinqDataSource>
This all works fine when the page first loads. The Category list contains the all the available category values, and the first category in the list is selected. And the corresponding Articles for the first category are displayed appropriately in the Article dropdown control. However, when I change the category (a post-back happens because I have it set to AutoPostBack="true"
, the Article dropdown does not get refreshed. In other words, the OnSelecting event is not getting fired on subsequent postbacks. Is this the expected bahaviour? If it is, how do I get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在 CategoryDropDownList 的 SelectedIndexChanged 事件中对 DropDownList 调用 DataBind。它不会自行发生。
例如
You need to call DataBind on the DropDownList in the CategoryDropDownList's SelectedIndexChanged event. It doesn't happen on its own.
e.g.