这篇文章将为大家详细讲解有关怎么在GridView中使用asp.net Checbox,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
成都创新互联服务项目包括怀远网站建设、怀远网站制作、怀远网页制作以及怀远网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,怀远网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到怀远省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!后台代码:
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; }
关于怎么在GridView中使用asp.net Checbox就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。