时间:2021-05-28
本文实例讲述了asp.net Checbox在GridView中的应用方法。分享给大家供大家参考,具体如下:
先看效果图:
前台代码:样式自己定义哦!
<div style="text-align: center; width: 80%"> <yxy:HkrGridView ID="tabGridView1" runat="server" AutoGenerateColumns="False" Width="100%" OnRowDataBound="HkrGridView1_RowDataBound" OnRowCreated="HkrGridView1_RowCreated" ShowHeader="True" AllowPaging="false" DataKeyNames="keyId" ShowFooter="false"> <Columns> <asp:BoundField> <ItemStyle HorizontalAlign="Center" Width="5%" /> </asp:BoundField> <asp:TemplateField> <ItemTemplate> <a href='<%#DataBinder.Eval(Container.DataItem,"newName")%>' ><%#DataBinder.Eval(Container.DataItem,"oldName")%></a> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="memo"> <ItemStyle Width="20%" HorizontalAlign="left" /> </asp:BoundField> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="CheckBox" runat="server" /> </ItemTemplate> <ItemStyle HorizontalAlign="Center" Width="5%" /> </asp:TemplateField> </Columns> <FooterStyle ForeColor="Red" HorizontalAlign="Center" Font-Bold="true" /> </yxy:HkrGridView> <div id="DivOne" style="text-align: right"> <asp:CheckBox ID="CheckBoxAll" runat="server" Text="全选" Width="80px" AutoPostBack="True" OnCheckedChanged="CheckBoxAll_CheckedChanged" /> <asp:CheckBox ID="CheckBox1" runat="server" Text="反选" Width="80px" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged" /> <asp:Button ID="Button1" runat="server" Text="取 消" CssClass="Button" OnClick="Button1_Click" /> </div></div>后台代码:
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 = "序号<BR>No."; tcHeader.Add(new TableHeaderCell()); tcHeader[1].Text = "附件名称"; tcHeader.Add(new TableHeaderCell()); tcHeader[2].Text = "备注"; tcHeader.Add(new TableHeaderCell()); tcHeader[3].Text = "选择</tr>"; }}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程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了asp.net中的GridView分页问题。分享给大家供大家参考。具体分析如下:在ASP.NET中,经常会使用到GridView的分页,一般情况下
本文实例讲述了asp.net获取ListView与gridview中当前行的行号。分享给大家供大家参考,具体如下:aspx中,在gridview/ListVie
本文实例讲述了asp.net实现固定GridView标题栏的方法。分享给大家供大家参考,具体如下:
asp.net操作access数据库是常见的数据库操作应用,本文就来实例讲解一下asp.net实现access数据库分页的方法。希望对大家的asp.net程序设
本文实例讲述了asp.net中GridView编辑,更新,合计用法。分享给大家供大家参考,具体如下:前台代码:注意:1、通过设置ReadOnly="True"表