码迷,mamicode.com
首页 > 其他好文 > 详细

Repeater中绑定DropDownList

时间:2015-09-18 18:31:31      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

效果如图:

技术分享

 

 

 

 

技术分享

后台代码如下 :

/// <summary>
/// 动态绑定Repeater中的指派下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void rptContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList dllOperator = (DropDownList)e.Item.FindControl("dllOperator");
dllOperator.DataSource = AdminUserService.GetList("");
dllOperator.DataTextField = "realName";
dllOperator.DataValueField = "id";
dllOperator.DataBind();
dllOperator.Items.Insert(0,new ListItem("请选择", "-99"));
//找到分类Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;//获取当前项行数据再去访问那一列.注意坐标索引是从0开始

dllOperator.SelectedValue = rowv[4].ToString();
}
}

 

前台代码:

 

    <asp:Repeater ID="repInfo" runat="server"   OnItemDataBound="rptContent_ItemDataBound">

 

  <asp:DropDownList ID="dllOperator" runat="server"></asp:DropDownList>

 

Repeater中绑定DropDownList

标签:

原文地址:http://www.cnblogs.com/lk516924/p/4819869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!