当前位置:首页 > GridView控件的使用
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow) {
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) {
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add(\你确认要删除:\\\吗?')\ } }
}
9.GridView实现自动编号:
效果图:
实现方法:
双击GridView的OnRowDataBound事件;
在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
//如果是绑定数据行 //清清月儿http://blog.csdn.net/21aspnet
if (e.Row.RowType == DataControlRowType.DataRow) {
////鼠标经过时,行背景色变
//e.Row.Attributes.Add(\ ////鼠标移出时,行背景色变
//e.Row.Attributes.Add(\
////当有编辑列时,避免出错,要加的RowState判断
//if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) //{
// ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add(\你确认要删除:\\\吗?')\ //}
}
if (e.Row.RowIndex != -1) {
int id = e.Row.RowIndex + 1; e.Row.Cells[0].Text = id.ToString(); }
}
注意这时最好把前台的第一列的表头该为“编号”,因为以前的第一列被“吃掉”了。
OnRowUpdating=\BackColor=\OnRowDataBound=\ 10.GridView实现自定义时间货币等字符串格式: 效果图: 图1-未格式化前 图2-格式化后 解决方法: 在asp.net 2.0中,如果要在绑定列中显示比如日期格式等,如果用下面的方法是显示不了的 主要是由于htmlencode属性默认设置为true,已防止XSS攻击,安全起见而用的,所以,可以有以下两种方法解决 1、 HeaderText=\ 将htmlencode设置为false即可 另外的解决方法为,使用模版列
共分享92篇相关文档