Multi checkbox insert

Discussion in 'C#' started by devmonk, Sep 28, 2006.

  1. #1
    I have a form that is passing a number to check box values with the same name (productID) but different values (numerical values). It is also passing a warehouseID as a hidden field.

    I need to dump these values into an access table called wtbProductWarehouses with fields titled ProductID and WarehouseID. What is the code that I need to write to have it loop through all of the productID values and individually add each one to the db while also adding the warehouseID with it.

    Thanks so much!

    Jason
     
    devmonk, Sep 28, 2006 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    i would give each checkbox a Name in your html (created via script) like warehouseproduct_ProductID_WarehouseID

    <input name="warehouseproduct_3_12" />

    then iterate over all the posted form elements
    if the form element's first x chars equals "warehouseproduct_" then you know you are dealing with a checkbox. then do a Split of the form elements Name - and if the form elements value is checked. splitVar(1) = your productid and splitVar(2) = your warehouseID.

    Hope this helps - theirs plenty of source on the web for this :)
     
    ccoonen, Sep 28, 2006 IP