Repeater的Item项绑定DropDownList

前台页面:

 <asp:Repeater ID="rptJgtList" runat="server" OnItemDataBound="rptJgtList_ItemDataBound">                            
    <ItemTemplate>
       <tr class="danhao" zz-jincheng='<%#Eval("kxsjd_jincheng")%>'>
          <td width="15%">
            <asp:DropDownList ID="ddl_FBType" runat="server">
            </asp:DropDownList>
          </td>                                    
       </tr>
     </ItemTemplate>
 </asp:Repeater>

后台CS:

/// <summary>
    /// 绑定发包类型
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void rptJgtList_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        DropDownList ddl;
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            ddl= (DropDownList)e.Item.FindControl("ddl_FBType");

            DataTable dt = newCB.GetTableds("zab_userList", "u_xingming,u_kahao,u_id", " u_zhuangtaiyg<>'离职' and u_states<>4 and u_zuming='设计组'", "u_xingming", 0);
            ddl.DataSource = dt;
            ddl.DataTextField = "u_xingming";
            ddl.DataValueField = "u_kahao";
            ddl.DataBind();
        //为DropDownList添加一行
            ddl.Items.Insert(0, "集团设计院");
            ddl.Items.Insert(1, "外援");

            if (!string.IsNullOrEmpty(DataBinder.Eval(e.Item.DataItem, "kxsjd_type").ToString().Trim()))
            {
                try
                {
                    ddl.Items.FindByValue(DataBinder.Eval(e.Item.DataItem, "kxsjd_type").ToString()).Selected = true;
                }
                catch (Exception)
                {

                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('绘图员信息丢失,或者离职,无法加载,有问题请打集团网络部电话!');</script>");
                }
            }
        }
    }

 

posted @ 2014-05-23 10:19  Mr.Thanks  阅读(298)  评论(0编辑  收藏  举报