asp.net Checbox在GridView中的应用实例分析

本文实例讲述了asp.net Checbox在GridView中的应用方法。分享给大家供大家参考,具体如下:

先看效果图:

asp.net Checbox在GridView中的应用实例分析_第1张图片

前台代码:样式自己定义哦!

后台代码:

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 Checbox在GridView中的应用实例分析)