Application example Analysis of ASP.net checbox in GridView _ Practical skills

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.