怎样将LIST中的数据绑定到GridView,并实现增删改查

怎样将LIST中的数据绑定到GridView,并实现增删改查

我的一个GridView操作文件,数据源是实体LIST,删改查功能都有了,你参考下 using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using lwf_MVC.CTRL; using lwf_MVC.lwf_Normal; using lwf_MVC.MODEL; public partial class admin_news_edit : System.Web.UI.Page { public string icls_name = "cls_f_news"; //不同级数系列区别在于iWhere public string iWhere = " 1 = 1 and ENG = " + WEB.GQ("ENG", "0") + " and TID1 = " + WEB.GQ("SSS", "1") + " and 1 = 1"; public int getRecordCount() { cls_f_news if_news = (cls_f_news)CTRL.CreateModel(icls_name); if_news.title = soKey.Text; if_news.contents = soKey.Text; if_news.WHERE = iWhere; int i_recordcount = CTRL.getCount(if_news, "order by orderid,id desc"); return i_recordcount; } protected void Page_Load(object sender, EventArgs e) { if (WEB.getSession("userName") == null || WEB.getSession("userName") == "") JS.RD(System.Web.HttpUtility.UrlDecode("%e7%99%bb%e9%99%86%e8%b6%85%e6%97%b6%2c%e8%af%b7%e9%87%8d%e6%96%b0%e7%99%bb").Trim(), "../login.aspx"); if (!IsPostBack) { AspNetPagerBin(1); GridViewBin(); } } protected void AspNetPagerBin(int curr) { int i_recordcount = getRecordCount(); AspNetPager1.RecordCount = i_recordcount; AspNetPager1.CurrentPageIndex = curr; } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; GridViewBin(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; GridViewBin(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { int i_id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); cls_f_news baseTableObj = (cls_f_news)CTRL.CreateModel(icls_name, i_id); baseTableObj.title = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString(); baseTableObj.newfrom = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.ToString(); baseTableObj.addTime = DateTime.Parse(((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToString()); baseTableObj.orderid = int.Parse(((TextBox)GridView1.Rows[e.RowIndex].FindControl("tb_orderid_b")).Text.ToString()); if (CTRL.Update(baseTableObj)) { JS.alert(System.Web.HttpUtility.UrlDecode("%e4%bf%ae%e6%94%b9%e6%88%90%e5%8a%9f").Trim()); } else { JS.alert(System.Web.HttpUtility.UrlDecode("%e7%bd%91%e7%bb%9c%e8%b6%85%e6%97%b6%ef%bc%8c%e8%af%b7%e9%87%8d%e6%96%b0%e5%86%8d%e8%af%95").Trim()); } //==================================== GridView1.EditIndex = -1; GridViewBin(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int i_id = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); cls_f_news baseTableObj = (cls_f_news)CTRL.CreateModel(icls_name, i_id); if (CTRL.Delete(baseTableObj)) { JS.alert(System.Web.HttpUtility.UrlDecode("%e8%ae%b0%e5%bd%95%e5%88%a0%e9%99%a4%e6%88%90%e5%8a%9f").Trim()); } else { JS.alert(System.Web.HttpUtility.UrlDecode("%e7%bd%91%e7%bb%9c%e8%b6%85%e6%97%b6%ef%bc%8c%e8%af%b7%e9%87%8d%e6%96%b0%e5%86%8d%e8%af%95").Trim()); } //==================================== GridView1.EditIndex = -1; GridViewBin(); } protected void AspNetPager1_PageChanged(object sender, EventArgs e) { GridView1.EditIndex = -1; GridView1.PageIndex = AspNetPager1.CurrentPageIndex; GridViewBin(); } protected void CheckBox_all_CheckedChanged(object sender, EventArgs e) { CheckBox_opp.Checked = false; for (int i_i = 0; i_i <= GridView1.Rows.Count - 1; i_i++) { CheckBox ckb = (CheckBox)GridView1.Rows[i_i].FindControl("cb_selBoxs"); if (CheckBox_all.Checked) { ckb.Checked = true; } else { ckb.Checked = false; } } } protected void CheckBox_opp_CheckedChanged(object sender, EventArgs e) { CheckBox_all.Checked = false; for (int i_i = 0; i_i <= GridView1.Rows.Count - 1; i_i++) { CheckBox ckb = (CheckBox)GridView1.Rows[i_i].FindControl("cb_selBoxs"); if (ckb.Checked) { ckb.Checked = false; } else { ckb.Checked = true; } } } protected void lb_delete_Click(object sender, EventArgs e) { for (int i_i = 0; i_i <= GridView1.Rows.Count - 1; i_i++) { CheckBox ckb = (CheckBox)GridView1.Rows[i_i].FindControl("cb_selBoxs"); if (ckb.Checked) { int i_id = int.Parse(GridView1.DataKeys[i_i].Value.ToString()); cls_f_news baseTableObj = (cls_f_news)CTRL.CreateModel(icls_name, i_id); CTRL.Delete(baseTableObj); } } int i_Pcount = getRecordCount(); if (AspNetPager1.CurrentPageIndex > i_Pcount) { AspNetPagerBin(i_Pcount); } else { AspNetPagerBin(AspNetPager1.CurrentPageIndex); } GridViewBin(); } protected void lb_order_Click(object sender, EventArgs e) { for (int i_i = 0; i_i <= GridView1.Rows.Count - 1; i_i++) { TextBox tb = (TextBox)GridView1.Rows[i_i].FindControl("tb_orderid_a"); int i_id = int.Parse(GridView1.DataKeys[i_i].Value.ToString()); cls_f_news baseTableObj = (cls_f_news)CTRL.CreateModel(icls_name, i_id); baseTableObj.orderid = int.Parse(tb.Text.ToString()); CTRL.Update(baseTableObj); } GridViewBin(); } protected void bt_search_Click(object sender, EventArgs e) { AspNetPagerBin(1); GridViewBin(); } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int rowNum; int id_i; } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { } } protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) { string sortExpression = e.SortExpression; ViewState["sortExpression"] = sortExpression; if (ViewState["ASC"].ToString() == "0") { ViewState["ASC"] = "1"; } else { ViewState["ASC"] = "0"; } AspNetPagerBin(1); GridViewBin(); } protected void GridViewBin() { CheckBox_all.Checked = false; cls_f_news if_news = (cls_f_news)CTRL.CreateModel(icls_name); if_news.title = soKey.Text; if_news.contents = soKey.Text; if_news.WHERE = iWhere; int RecordCount; int curP = Convert.ToInt32(AspNetPager1.CurrentPageIndex); List<cls_f_news> iList_f_news = CTRL.getPageList(if_news, "order by orderid,id desc", AspNetPager1.PageSize, curP, out RecordCount).ConvertAll<cls_f_news>(delegate(lwf_MVC.MODEL.baseTable s) { return (cls_f_news)s; }); if (ViewState["ASC"] == null) ViewState["ASC"] = "-1"; if (ViewState["sortExpression"] == null) ViewState["sortExpression"] = "orderid"; if (ViewState["ASC"].ToString() == "-1") { iList_f_news.Sort(delegate(cls_f_news a, cls_f_news b) { return (new CaseInsensitiveComparer()).Compare(a.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(a, null), b.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(b, null)); }); } else { if (ViewState["ASC"].ToString() == "1") { iList_f_news.Sort(delegate(cls_f_news a, cls_f_news b) { return (new CaseInsensitiveComparer()).Compare(a.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(a, null), b.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(b, null)); }); } else { iList_f_news.Sort(delegate(cls_f_news a, cls_f_news b) { return (new CaseInsensitiveComparer()).Compare(b.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(b, null), a.GetType().GetProperty(ViewState["sortExpression"].ToString()).GetValue(a, null)); }); } } GridView1.DataSource = iList_f_news; GridView1.DataKeyNames = new string[] { "id" }; GridView1.DataBind(); } }

聚圣源西甲德比失恋33天李可扮演者汉化包jiqingshipin王姓起名比较有内涵的趣味设计不说再见电视剧免费观看怎么给文化公司起名杜姓起名字国语版动画片劫后余生无限子弹公司免费起名测名网两个环烷烃连在一起怎么命名按生辰八字免费起名论语起名字回到2002当医生文库下载电梯公司起名字和晟字搭配起公司名起名字 宝宝五行缺土ppp85根据八字免费起什么名字好听神界危机5.0隐藏英雄一字取名起名大全男孩名字泉州电信欢乐颂百度云美名腾起名布雷斯塔警长国语enableeventvalidation鼠年的婴儿起名大全淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻让美丽中国“从细节出发”清明节放假3天调休1天男孩疑遭霸凌 家长讨说法被踢出群国产伟哥去年销售近13亿网友建议重庆地铁不准乘客携带菜筐雅江山火三名扑火人员牺牲系谣言代拍被何赛飞拿着魔杖追着打月嫂回应掌掴婴儿是在赶虫子山西高速一大巴发生事故 已致13死高中生被打伤下体休学 邯郸通报李梦为奥运任务婉拒WNBA邀请19岁小伙救下5人后溺亡 多方发声王树国3次鞠躬告别西交大师生单亲妈妈陷入热恋 14岁儿子报警315晚会后胖东来又人满为患了倪萍分享减重40斤方法王楚钦登顶三项第一今日春分两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?周杰伦一审败诉网易房客欠租失踪 房东直发愁男子持台球杆殴打2名女店员被抓男子被猫抓伤后确诊“猫抓病”“重生之我在北大当嫡校长”槽头肉企业被曝光前生意红火男孩8年未见母亲被告知被遗忘恒大被罚41.75亿到底怎么缴网友洛杉矶偶遇贾玲杨倩无缘巴黎奥运张立群任西安交通大学校长黑马情侣提车了西双版纳热带植物园回应蜉蝣大爆发妈妈回应孩子在校撞护栏坠楼考生莫言也上北大硕士复试名单了韩国首次吊销离岗医生执照奥巴马现身唐宁街 黑色着装引猜测沈阳一轿车冲入人行道致3死2伤阿根廷将发行1万与2万面值的纸币外国人感慨凌晨的中国很安全男子被流浪猫绊倒 投喂者赔24万手机成瘾是影响睡眠质量重要因素春分“立蛋”成功率更高?胖东来员工每周单休无小长假“开封王婆”爆火:促成四五十对专家建议不必谈骨泥色变浙江一高校内汽车冲撞行人 多人受伤许家印被限制高消费

聚圣源 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化