您现在的位置是:网站首页> 编程资料编程资料
asp.net Checbox在GridView中的应用实例分析_实用技巧_
2023-05-24
401人已围观
简介 asp.net Checbox在GridView中的应用实例分析_实用技巧_
本文实例讲述了asp.net Checbox在GridView中的应用方法。分享给大家供大家参考,具体如下:
先看效果图:

前台代码:样式自己定义哦!
后台代码:
protected void HkrGridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { TableCellCollection tcHeader = e.Row.Cells; tcHeader.Clear(); //第一行表头 tcHeader.Add(new TableHeaderCell()); tcHeader[0].Text = "序号
No."; tcHeader.Add(new TableHeaderCell()); tcHeader[1].Text = "附件名称"; tcHeader.Add(new TableHeaderCell()); tcHeader[2].Text = "备注"; tcHeader.Add(new TableHeaderCell()); tcHeader[3].Text = "选择"; } } protected void HkrGridView1_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow gr = e.Row; if (e.Row.RowIndex != -1) { e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString(); } } private void HkrGridViewBind(){ string strSql = "SELECT keyId,newName, oldName, localHome,memo FROM aq_file_up WHERE (relaid = @relaid) AND (fjType = @fjType) AND (usestatus = 1)"; SqlParameter[] sps = { new SqlParameter("@relaid",this.hdnRelaId.Value), new SqlParameter("@fjType",this.hdnFjType.Value) }; DataTable dt = pms.SqlHelper.ExecuteDataTable(CommandType.Text, strSql, sps); tabGridView1.DataSource = dt; tabGridView1.DataBind(); } rotected void Button1_Click(object sender, EventArgs e) { CheckBoxAll.Checked = false; CheckBox1.Checked = false; for (int i = 0; i <= tabGridView1.Rows.Count - 1; i++) { CheckBox cb = (CheckBox)tabGridView1.Rows[i].FindControl("CheckBox"); cb.Checked = false; } } protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { for (int i = 0; i <= tabGridView1.Rows.Count - 1; i++) { CheckBox cb = (CheckBox)tabGridView1.Rows[i].FindControl("CheckBox"); if (cb.Checked == false) { cb.Checked = true; } else { cb.Checked = false; } } //CheckBox1.Checked =true; CheckBoxAll.Checked = false; } protected void CheckBoxAll_CheckedChanged(object sender, EventArgs e) { for (int i = 0; i <= tabGridView1.Rows.Count - 1; i++) { CheckBox cb = (CheckBox)tabGridView1.Rows[i].FindControl("CheckBox"); if (CheckBoxAll.Checked == true) { cb.Checked = true; } else { cb.Checked = false; } } CheckBox1.Checked = false; } 更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net操作json技巧总结》、《asp.net字符串操作技巧汇总》、《asp.net操作XML技巧总结》、《asp.net文件操作技巧汇总》、《asp.net ajax技巧总结专题》及《asp.net缓存操作技巧总结》。
希望本文所述对大家asp.net程序设计有所帮助。
您可能感兴趣的文章:
- asp.net实现固定GridView标题栏的方法(冻结列功能)
- 在ASP.NET 2.0中操作数据之六十四:GridView批量添加数据
- 在ASP.NET 2.0中操作数据之十:使用 GridView和DetailView实现的主/从报表
- ASP.NET数据绑定GridView控件使用技巧
- ASP.NET数据绑定之GridView控件
- ASP.NET中GridView的文件输出流方式
- ASP.NET中GridView、DataList、DataGrid三个数据控件foreach遍历用法示例
- asp.net GridView中使用RadioButton单选按钮的方法
- ASP.NET中GridView 重复表格列合并的实现方法
相关内容
- asp.net中GridView编辑,更新,合计用法示例_实用技巧_
- ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统之前端页面框架构建源码分享_实用技巧_
- .Net MVC网站中配置文件的读写_实用技巧_
- ASP.NET MVC5网站开发之网站设置(九)_实用技巧_
- ASP.NET MVC结合JavaScript登录、校验和加密_实用技巧_
- java selenium智能等待页面加载完成示例代码_实用技巧_
- asp.net下的异步加载_实用技巧_
- 微信公众号支付(MVC版本)_实用技巧_
- 拥有网页版小U盘 ASP.NET实现文件上传与下载功能_实用技巧_
- ASP.NET中GridView的文件输出流方式_实用技巧_
