/// <summary> /// 获得数据列表 /// </summary> public List <zs.Model.Tbl_Zhuanye> DataTableToList(DataTable dt) { List <zs.Model.Tbl_Zhuanye> modelList = new List <zs.Model.Tbl_Zhuanye>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { zs.Model.Tbl_Zhuanye model; for (int n = 0; n < rowsCount; n++) { model = new zs.Model.Tbl_Zhuanye(); if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "") { model.id = int.Parse(dt.Rows[n]["id"].ToString()); } if (dt.Rows[n]["name"] != null && dt.Rows[n]["name"].ToString() != "") { model.name = dt.Rows[n]["name"].ToString(); } if (dt.Rows[n]["cont"] != null && dt.Rows[n]["cont"].ToString() != "") { model.cont = dt.Rows[n]["cont"].ToString(); } if (dt.Rows[n]["xueyuanid"] != null && dt.Rows[n]["xueyuanid"].ToString() != "") { model.xueyuanid = int.Parse(dt.Rows[n]["xueyuanid"].ToString()); } modelList.Add(model); } } return(modelList); }
private void BindData() { zs.BLL.Tbl_Xueyuan bllg = new zs.BLL.Tbl_Xueyuan(); this.ddl_xueyuanid.DataSource = bllg.GetModelList(""); this.ddl_xueyuanid.DataTextField = "name"; this.ddl_xueyuanid.DataValueField = "id"; this.ddl_xueyuanid.DataBind(); if (Request.QueryString["id"] != null) { string ids = Request.QueryString["id"].ToString(); if (ids != "0") { zs.Model.Tbl_Zhuanye model = bll.GetModel(int.Parse(ids)); this.tb_name.Text = model.name; //this.tb_cont.Html = model.cont; this.ddl_xueyuanid.SelectedValue = model.xueyuanid.Value.ToString(); this.btn_add.Text = "修改"; } } }
protected void btn_add_Click(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { string ids = Request.QueryString["id"].ToString(); if (ids != "0") { zs.Model.Tbl_Zhuanye model = bll.GetModel(int.Parse(ids)); model.name = this.tb_name.Text.Trim(); //model.cont = this.tb_cont.Html; model.xueyuanid = int.Parse(this.ddl_xueyuanid.SelectedValue); bll.Update(model); BindData(); } else { zs.Model.Tbl_Zhuanye model = new zs.Model.Tbl_Zhuanye(); model.name = this.tb_name.Text.Trim(); //model.cont = this.tb_cont.Html; model.xueyuanid = int.Parse(this.ddl_xueyuanid.SelectedValue); bll.Add(model); } } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(zs.Model.Tbl_Zhuanye model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(zs.Model.Tbl_Zhuanye model) { return(dal.Add(model)); }