The application of ASP.net checbox in GridView is described in this paper. Share to everyone for your reference, specific as follows:
First look at the effect of the picture:
Foreground code: Style own Definition Oh!
<div style= "Text-align:center; width:80% "> <yxy:hkrgridview id=" tabGridView1 "runat=" Server "autogeneratecolumns=" False "width=" 100% "Onro Wdatabound= "Hkrgridview1_rowdatabound" onrowcreated= "hkrgridview1_rowcreated" showheader= "True" AllowPaging= " False "datakeynames=" keyID "showfooter=" false "> <Columns> <asp:BoundField> <itemsty Le horizontalalign= "Center" width= "5%"/> </asp:BoundField> <asp:TemplateField> <it emtemplate> <a href= ' <% #DataBinder. Eval (Container.DataItem, "NewName")%> ' ><% #DataBinder. Eval ( Container.DataItem, "Oldname")%></a> </ItemTemplate> </asp:TemplateField> <asp:b Oundfield datafield= "Memo" > <itemstyle width= "20%" horizontalalign= "left"/> </asp:boundfield&
Gt <asp:TemplateField> <ItemTemplate> <asp:checkbox id= "checkbox" runat= "server"/> </ItemTemplate> <itemstyle horizontalalign=" Center "width=" 5% "/> </asp:te
mplatefield> </Columns> <footerstyle forecolor= "Red" horizontalalign= "Center" font-bold= "true"/> </yxy:HkrGridView> <div id= "Divone" style= "Text-align:right" > <asp:checkbox id= "Checkboxall" R unat= "Server" text= "Select All" width= "80px" autopostback= "True" oncheckedchanged= "checkboxall_checkedchanged"/> & Lt;asp:checkbox id= "CheckBox1" runat= "Server" text= "width=" 80px "autopostback=" True "oncheckedchanged=" CheckBox 1_checkedchanged "/> <asp:button id=" Button1 "runat=" Server "text=" Cancel "cssclass=" button "onclick=" Button1_clic
K "/> </div> </div>
Background code:
protected void hkrgridview1_rowcreated (object sender, GridViewRowEventArgs e) {if (E.row.rowtype = = Datacontrolrowty Pe.
Header) {tablecellcollection tcheader = e.row.cells;
Tcheader.clear ();
The first row of header Tcheader.add (new Tableheadercell ()); Tcheader[0].
Text = "ordinal <br>no.";
Tcheader.add (New Tableheadercell ()); TCHEADER[1].
Text = "attachment name";
Tcheader.add (New Tableheadercell ()); TCHEADER[2].
Text = "Remarks";
Tcheader.add (New Tableheadercell ()); TCHEADER[3].
Text = "Select </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 whe
RE (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.Cou nt-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; } protectedvoid 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;
}
More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."
I hope this article will help you to ASP.net program design.