首页 > 代码库 > gridview使用技巧
gridview使用技巧
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); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。