asp.net – Repeater中DropDownList的SelectedValue
发布时间:2020-05-28 14:19:34 所属栏目:asp.Net 来源:互联网
导读:如何在转发器中设置dropDownList的选定项? 转发器绑定到repeaterData DataTable,dropDownList绑定到后面的代码中的dropDownList DataTable.我需要将DropDownList的SelectedValue属性设置为repeaterData表中的字段值. 这就是我尝试过的: asp:Repeater runat=
|
如何在转发器中设置dropDownList的选定项? 转发器绑定到repeaterData DataTable,dropDownList绑定到后面的代码中的dropDownList DataTable.我需要将DropDownList的SelectedValue属性设置为repeaterData表中的字段值. 这就是我尝试过的: <asp:Repeater runat="server" ID="myRepeater>
<ItemTemplate>
<asp:DropDownList runat="server" CssClass="fullSelect" ID="degree_dropdown"
AppendDataBoundItems="true"
selectedValue='<%#DataBinder.Eval(Container.DataItem,"degreeCode")%>'>
<asp:ListItem Text="Select Degree" />
</asp:DropDownList>
</ItemTemplate>
</asp:Repeater>
填充转发器的代码: myRepeater.DataSource = myRepeaterData; //myRepeaterData is a datatable myRepeater.DataBind(); 用于填充下拉列表的代码: protected void educationPopup_repeater_ItemDataBound(object sender,RepeaterItemEventArgs e)
{
DropDownList degree_dropdown = e.Item.FindControl("degree_dropdown") as DropDownList;
if (degree_dropdown != null)
{
degree_dropdown.DataSource = degrees; //a datatable
degree_dropdown.DataTextField = "degree";
degree_dropdown.DataValueField = "code";
degree_dropdown.DataBind();
}
}
解决方法你快到了.您只需要将DataItem转换为DataRowView,并将其分配给DropDownList,如下所示 –protected void myRepeater_ItemDataBound(object sender,RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
var degree_dropdown = e.Item.FindControl("degree_dropdown") as DropDownList;
string degreeCode = (string) ((DataRowView) e.Item.DataItem)["degreeCode"];
if (degree_dropdown != null)
{
degree_dropdown.DataSource = degrees; //a datatable
degree_dropdown.DataTextField = "degree";
degree_dropdown.DataValueField = "code";
degree_dropdown.DataBind();
if (degree_dropdown.Items.FindByValue(degreeCode) != null)
degree_dropdown.SelectedValue = degreeCode;
}
}
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ASP.NET MVC是否允许私有ViewModel构造函数
- ASP.net应用程序的最佳perfmon计数器是什么?
- asp.net-mvc – Bug? ASP.NET MVC 2中的客户端验证导致Val
- ASP.NET MVC Project和App_Code文件夹
- ASP.NET,C#,IIS,MIME类型,文件上传条件
- asp.net-mvc – Redirect和RedirectToAction之间的混淆
- asp.net web大文件上传带进度条实例代码
- asp.net – 如何在aspx页面中显示pdf?
- ASP.NET URL验证
- asp.net-mvc – MVC 5继承的脚手架使用错误的实体集
推荐文章
站长推荐
- ASP.NET十七种正则表达试
- asp.net-mvc – LINQ Distinct()
- asp.net-web-api – 从asp.net web api定制odata
- asp.net – 通过使用Javascript将邮政编码传递到
- asp.net – 在VS Code中指定localhost端口的位置
- ASP.NET MVC 3可以在ASP.NET 3.5网站中运行吗?
- ASP.Net – 在负载平衡环境中处理会话数据?
- asp.net-mvc – MVC3中的CheckboxList查看并获取
- asp.net-mvc – MVC 5渲染视图到字符串
- asp.net-mvc – 具有适当的敲除绑定的网格小部件
热点阅读
