从EntityDataSource填充的ascx中的DropDownList,如何设置选中的值?

时间:2014-06-17 13:30:01

标签: c# asp.net drop-down-menu selectedindex entitydatasource

我在.ascx用户控件中有以下DropDownList和EntityDataSource。因此,DropDownList正确填充了大约十几个条目。

<asp:DropDownList ID="ddlStudents" runat="server" DataTextField="nickname" DataValueField="id"
    DataSourceID="edsCurrentStudents">
</asp:DropDownList>

<asp:EntityDataSource ID="edsCurrentStudents" runat="server" ContextTypeName="StudentTracker.dbEntities"
EnableFlattening="False" EntitySetName="Students" Select="it.id, it.nickname, it.firstName"
OrderBy="it.firstName" Where="it.Current = true">
</asp:EntityDataSource>

我有一个aspx页面,其中包含许多这些用户控件,我需要以不同的方式(以编程方式)设置每个用户控件的选定值,但我不知道在哪里放置代码,因为我希望它在数据源填充DDL之后运行。我知道如何在DDL上设置SelectedIndex,并且可以像这样搜索和分配:

DDL.SelectedIndex = DDL.Items.IndexOf(DDL.Items.FindByText("TargetText"));

...但是还没有弄清楚从EntityDataSource填充的列表是如何或在何处进行的。页面中的事件?在控制?或者在页面加载后粘贴一些javascript以在客户端上运行?

感谢您的帮助。代码非常感谢 -

0 个答案:

没有答案
相关问题