GridView的其他用法小总结
GridView实现删除时弹出确认对话框:
View Code
View Code
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
2 {
3 ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
4 }
如图
DataView前自动生成编号
同样也是RowDataBound方法加上下面一段代码就ok了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 if (e.Row.RowIndex != -1)
2 {
3 int id = e.Row.RowIndex + 1;
4 e.Row.Cells[0].Text = id.ToString();
5 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步