void drp_DataBinding(object sender, EventArgs e) { DropDownList drp = (DropDownList)sender; GridViewRow gr = (GridViewRow)drp.NamingContainer; BLL.T_UsersInfo_BLL Ubll = new DigiPower.Onlinecol.Standard.BLL.T_UsersInfo_BLL(); DataSet ds = Ubll.GetAllList(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { ListItem item = new ListItem(); item.Text = ds.Tables[0].Rows[i]["UserName"].ToString(); item.Value = ds.Tables[0].Rows[i]["UserID"].ToString(); drp.Items.Add(item); } //关键位置 //使用DataBinder.Eval绑定数据 //ProName,MyTemplate的属性.在创建MyTemplate实例时,为此属性赋值(数据源字段) string ArlistID = DataBinder.Eval(gr.DataItem, "FileListID").ToString(); BLL.T_FileList_BLL Abll = new DigiPower.Onlinecol.Standard.BLL.T_FileList_BLL(); Model.T_FileList_MDL Amodel = new DigiPower.Onlinecol.Standard.Model.T_FileList_MDL(); Amodel = Abll.GetModel(Common.ConvertEx.ToInt(ArlistID)); if (Amodel != null) { drp.SelectedValue = Amodel.OperateUserID.ToString(); } }
public void DataBindEx2(int CompanyID, bool bIncludeAll) { BLL.T_UsersInfo_BLL otherBLL = new DigiPower.Onlinecol.Standard.BLL.T_UsersInfo_BLL(); DataSet ds = otherBLL.GetListByCompany("CompanyID=" + CompanyID); CheckBoxList1.DataValueField = "UserID"; CheckBoxList1.DataTextField = "UserName"; CheckBoxList1.DataSource = ds; CheckBoxList1.DataBind(); if (bIncludeAll == true) { ListItem l1 = new ListItem(); l1.Text = "工程全体人员"; l1.Value = "0"; CheckBoxList1.Items.Insert(0, l1); } }