我在表单视图中有一个编辑按钮和一个下拉列表。我正在使用 Linq To Entities 来获取我需要使用的数据,并且在填充和查看 formview itemtemplate 时没有问题。
但是,下拉列表控件id="ddlEligibility"
(我现在得到的只是显示第一个值的下拉列表。我希望 itemtemplate 中的值默认显示,并且用户可以根据需要更改它。这是填充下拉列表的代码。有人有建议吗?edititemtemplate
itemtemplate
protected void btnEdit_Click(object sender, EventArgs e)
{
fvSubscriber.ChangeMode(FormViewMode.Edit);
fvSubscriber.DataBind();
LifeLineDSEntities context = new LifeLineDSEntities():
var program = from p in context.EligibilityPrograms
select p;
DropDownList ddlEligibility = (DropDownList)(fvSubscriber.FindControl("ddlEligibility")));
if (ddlEligibility != null)
{
ddlEligibility.DataSource = program;
ddlEligibility.DataTextField = "ProgramName";
ddlEligibility.DataValueField = "eligibilityCode";
ddlEligibility.DataBind();
}
}
FormView 中的下拉列表...
<form id="form1" runat="server">
<asp:FormView ID="fvSubscriber" runat="server" RenderOuterTable="false" DefaultMode="Readonly" OnModeChanging="fvSubscriberChanging">
<ItemTemplate>
<asp:TextBox ID="txtEligibility" runat="server" Text='<%# Eval("ProgramName") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlEligibility" runat="server" />
</EditItemTemplate>
</asp:FormView>
</form>