You need to select multiple items for a small project and modify the relevant data records:
The effect is as follows:
The specific implementation is as follows:
The gridview control is used.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------
Gridview is a control that provides related database operations. msdn explains: click here
Certificate ---------------------------------------------------------------------------------------------------------------------------------------
The procedure is as follows:
A. Key aspx code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderWidth="0px" Width="701px" ForeColor="Blue" Height="182px"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> <asp:HiddenField ID="HidID" runat="server" Value='<%# Bind("id") %> ' /> <asp:Label ID="Label1" runat="server" style="font-size:12px;color:#3344ff" Text='<%# Bind("content") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
B. key code in the aspx Background: (triggered by a button)
// Bind a value to the gridview
Public void BIND ()
{
String SQL;
SQL = "select ID, content from Intro ";
Gridview1.datasource = access. greatds (SQL );
Gridview1.databind ();
}
Protected void button#click (Object sender, eventargs e) {int rowcount = gridview1.rows. count; string STR = configurationmanager. connectionstrings ["kuny"]. connectionstring; oledbconnection conn = new oledbconnection (STR); Conn. open (); int tag = 0; For (INT I = 0; I <rowcount; I ++) {checkbox tempchk = (checkbox) gridview1.rows [I]. findcontrol ("checkbox1"); hiddenfield hidid = (hiddenfield) gridview1. Rows [I]. findcontrol ("hidid"); If (tempchk. checked = true) {string update_exam_item = "Update baoming_info set bk_exerm_id" + hidid. value + "=" + "1" + "where bk_exer_id =" + session ["stuid"]; // alert (update_exam_item); oledbcommand cmd = new oledbcommand (update_exam_item, conn); cmd. executenonquery (); tag ++ ;}} if (TAG = 0) {alert ("You must select at least one test item! ") ;}Else {conn. Close (); response. Redirect (" step_1.aspx ");}}
Summary:
For (INT I = 0; I <rowcount; I ++ ){
// Retrieve the checkbox and hide the text value through traversal.Checkbox tempchk = (checkbox) gridview1.rows [I]. findcontrol ("checkbox1"); hiddenfield hidid = (hiddenfield) gridview1.rows [I]. findcontrol ("hidid ");
//If (tempchk. checked = true) {string update_exam_item = "Update baoming_info set bk_exerm_id" + hidid. value + "=" + "1" + "where bk_exer_id =" + session ["stuid"]; // alert (update_exam_item); oledbcommand cmd = new oledbcommand (update_exam_item, conn); cmd. executenonquery (); tag ++ ;}}
To sum up, use the gridview control first, bind the data source BIND () to it, add the corresponding checkbox in the properties templatefield and itemtemplate of the gridview, and then trigger it with the button event for related operations.