updating database with checkboxes

前端 未结 2 2066
礼貌的吻别
礼貌的吻别 2021-01-23 12:31

i have a datagrid and every row has a checkbox on it. also every field in every row can be updated

the user can update multiple rows and check any checkboxes.

at

2条回答
  •  我在风中等你
    2021-01-23 13:01

    If you are using a GridView, building on the example from a previous example you got, you can do this. ** this is semi-pseudo code, beware**

    
    
        
          
              <%-- This is itemtemplate so they are visible by default --%>
                
                
             
          
          
          
          
          
          
        
    
    
    
    

    Code behind to process this

    public void btSubmit_Click(object sender, EventArgs e)
    {
      foreach (GridViewRow row in CustomersGridView.Rows) 
      {
        CheckBox cbVerify = (CheckBox)row.FindControl("cbVerify");
        HiddenField hidID = (HiddenField)row.FindControl("hidID");
    
        // Do your validation of the data here
        ..
    
        if (cbVerify != null)
        {
          // Add fields and update
          sqlRecord.UpdateParameters["ID"].DefaultValue = hidID.Value;
          sqlRecord.UpdateParameters["Valid"].DefaultValue = cbVerify.Checked.ToString();
          sqlRecord.Update();
        }
    }
    

    This should get you in a specific direction to look.

提交回复
热议问题