public List<Maticsoft.Model.Shop.Products.HotKeyword> DataTableToList(DataTable dt) { List<Maticsoft.Model.Shop.Products.HotKeyword> list = new List<Maticsoft.Model.Shop.Products.HotKeyword>(); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { Maticsoft.Model.Shop.Products.HotKeyword item = new Maticsoft.Model.Shop.Products.HotKeyword(); if ((dt.Rows[i]["Id"] != null) && (dt.Rows[i]["Id"].ToString() != "")) { item.Id = int.Parse(dt.Rows[i]["Id"].ToString()); } if ((dt.Rows[i]["Keywords"] != null) && (dt.Rows[i]["Keywords"].ToString() != "")) { item.Keywords = dt.Rows[i]["Keywords"].ToString(); } if ((dt.Rows[i]["CategoryId"] != null) && (dt.Rows[i]["CategoryId"].ToString() != "")) { item.CategoryId = new int?(int.Parse(dt.Rows[i]["CategoryId"].ToString())); } list.Add(item); } } return list; }
protected void btnAdd_Click(object sender, EventArgs e) { int num = Globals.SafeInt(this.dropCategories.SelectedValue, -1); if (num == -1) { MessageBox.ShowFailTip(this, "请选择商品分类"); } else { Maticsoft.Model.Shop.Products.HotKeyword model = new Maticsoft.Model.Shop.Products.HotKeyword { Keywords = this.tbKeyWord.Text.Trim(), CategoryId = new int?(num) }; if (this.hotKeywordBll.Add(model) > 0) { MessageBox.ShowSuccessTip(this, "添加成功!"); } else { MessageBox.ShowFailTip(this, "保存失败!"); } this.gridView.OnBind(); } }