码迷,mamicode.com
首页 > 其他好文 > 详细

gridview使用技巧

时间:2014-08-06 18:24:01      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   使用   io   ar   cti   

    
1、CheckBox模板选择事件
//多选业务员事件 protected void cbSelect_CheckedChanged(object sender, EventArgs e) { string pNames=lblPersonNames.Text; personList = new List<string>(pNames.Split(new string[]{","},StringSplitOptions.RemoveEmptyEntries)); CheckBox cbSelect = (CheckBox)sender; DataControlFieldCell dcf = (DataControlFieldCell)cbSelect.Parent; //父对象Cell GridViewRow gr = (GridViewRow)dcf.Parent; //父对象row if (cbSelect.Checked) { personList.Add(gr.Cells[0].Text); } else { personList.Remove(gr.Cells[0].Text); } lblPersonNames.Text = string.Join(",", personList.ToArray()); }
    
2、行绑定事件
protected void gvPerson_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string pNames = lblPersonNames.Text; personList = new List<string>(pNames.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)); string personName=e.Row.Cells[0].Text; if (personList.Contains(personName)) { CheckBox cbSelect=(CheckBox)e.Row.FindControl("cbSelect"); cbSelect.Checked = true; } } }

 

   附加:javascript数组扩展方法
Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index > -1) { this.splice(index, 1); } }

 

gridview使用技巧,布布扣,bubuko.com

gridview使用技巧

标签:style   blog   color   java   使用   io   ar   cti   

原文地址:http://www.cnblogs.com/kedarui/p/3894936.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!