Ivonne Aspilcueta

Ivonne Aspilcueta

  • 1.1k
  • 607
  • 8.8k

how to submit a form that contains text boxes, checkboxes and dropdown

Nov 20 2024 12:40 AM

Hello,

I build some code, but I am still missing some part of the puzzle, what I am trying to do is how to submit a form that contains text boxes, checkboxes and dropdown list to a database in web form asp.net.

It gives me an error as well: 

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS7036: There is no argument given that corresponds to the required formal parameter 'sender' of 'Subpoena.Button1_Click(object, EventArgs)'

Source Error:

Thank you

    public partial class Subpoena : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Create a list of month names

            string[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };



            // Add each month to the dropdown list

            foreach (string frommonth in months)

            {

                fromMonth.Items.Add(new ListItem(frommonth, frommonth));
               

            }

            foreach (string tomonth in months)

            {

             
                toMonth.Items.Add(new ListItem(tomonth, tomonth));

            }

            // Create a list of Year

            if (!IsPostBack)

            {
              

                fromYear.Items.Clear();
                fromYear.Items.Add("From Year");
                var currentYear = DateTime.Today.Year;
                for (int i = 7; i >= 0; i--)
                {
                    // Now just add an entry that's the current year minus the counter
                    fromYear.Items.Add((currentYear - i).ToString());
                }

            }
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
                                    
                    // Extract values from textboxes
                    int memberacct = int.Parse(memberAcct.Text);
                    string membername = memberName.Text;
                    duedate.Text = DateTime.Now.AddDays(3).ToString("dd/MM/yyyy");


                    // Extract values from dropdownlist
                    string frommonth = fromMonth.SelectedValue;
                    string tomonth = toMonth.SelectedValue;

            // Insert the data into the database
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ToString()))
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("INSERT INTO Main (@memberNumber,@memberName, @fromMonth, @fromYear, @toMonth, @toYear, @dueDate)", connection);

                cmd.Parameters.AddWithValue("@memberNumber", memberacct);
                cmd.Parameters.AddWithValue("@memeberName", membername);
                cmd.Parameters.AddWithValue("@fromMonth", frommonth);
                cmd.Parameters.AddWithValue("@fromYear", fromYear);
                cmd.Parameters.AddWithValue("@toMonth", tomonth);
                cmd.Parameters.AddWithValue("@toYear", toYear);
                cmd.Parameters.AddWithValue("@dueDate", duedate);
                cmd.Parameters.AddWithValue("@imageData", toMonth);

                cmd.ExecuteNonQuery();
                connection.Close();

                Response.Write("Image has been Added");

            }





        }

        
    }
<body>
    <div id="container">
            <div id="header">
                <img src="Styles/Wescom Credit Union Logo Color.jpg" alt="Wescom Color Logo"/>
                <h1>SUBPOENA FORM</h1>
            </div>
    <div id="content">
          <form class="form-inline" id="form1" runat="server">

                <table style="width:80%">
                    <tr>
                        <th class="label_left"><br/><asp:Label ID="Label1" runat="server" Text="Member Account"></asp:Label></th>
                        <th><br/>
                                <asp:TextBox ID="memberAcct" runat="server" tabindex="1" CssClass="myTextarea"></asp:TextBox>
                        </th>

                        <td><br/>
                                <asp:DropDownList ID="fromMonth" runat="server" tabindex="4" CssClass="DropDownList">
                                <asp:ListItem Text="From Month" Value="select" Selected="True"></asp:ListItem>
                                </asp:DropDownList>
                       </td>
                       <td><br/>
                                <asp:DropDownList ID="fromYear" runat="server" tabindex="5" CssClass="DropDownList">
                                <asp:ListItem Value="select" Selected="True"></asp:ListItem>
                                </asp:DropDownList>
                       </td>
                       
                       <td><br/>
                                <asp:DropDownList ID="toMonth" runat="server" tabindex="6" CssClass="DropDownList">
                                <asp:ListItem Text="To Month" Value="select" Selected="True"></asp:ListItem>
                                </asp:DropDownList>
                        </td>
                        <td><br/>
                                <asp:DropDownList ID="toYear" runat="server" tabindex="7" CssClass="DropDownList">
                                <asp:ListItem Text="To Year" Value="select" Selected="True"></asp:ListItem>
                                </asp:DropDownList>
                        </td>

                </tr>
                <tr>
                    <th class="label_left"><asp:Label ID="Label3" runat="server" Text="Member Name"></asp:Label></th>
                    <th>
                        <asp:TextBox ID="memberName" runat="server" tabindex="2" CssClass="myTextarea"></asp:TextBox>
                    </th>
               </tr>

               <tr>
                    <th class="label_left"><asp:Label ID="Label10" runat="server" Text="Due Date" ></asp:Label></th>
                <th>
                        <asp:TextBox ID="duedate" runat="server" tabindex="3" type="date" CssClass="myTextarea"></asp:TextBox> 
                </th>
             </tr>
           <tr> 
            
           <th><br/><br/><br/><br/>
              <asp:Label ID="Label2" runat="server" Text="Checks"></asp:Label>
              <asp:CheckBoxList  ID="ChecksBoxList" runat="server" tabindex="8" AutoPostBack = "true" CssClass="CheckBoxList">
                    <asp:ListItem Text="Branch Deposit Checks" Value="0"></asp:ListItem>
                    <asp:ListItem Text="ATM Deposit" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Snap Deposit" Value="2"></asp:ListItem>
                    <asp:ListItem Text="Mail Deposit" Value="3"></asp:ListItem>
                    <asp:ListItem Text="Share Drafts Check" Value="4"></asp:ListItem>
                    <asp:ListItem Text="Cashier Check" Value="5"></asp:ListItem>
                    <asp:ListItem Text="Money Order" Value="6"></asp:ListItem>
                    <asp:ListItem Text="Saving Bond" Value="7"></asp:ListItem>
                    <asp:ListItem Text="Select All" Value="All"></asp:ListItem>
               </asp:CheckBoxList>
           </th>
           <th><br/><br/>
                      <asp:Label ID="Label5" runat="server" Text="Member ID"></asp:Label>
                      <asp:CheckBoxList ID="MemberCheckBoxList" runat="server" tabindex="9" GroupName="receipts" OnCheckedChanged="CheckAll" CssClass="CheckBoxList">
                      <asp:ListItem Text="Joint ID" Value="Bangalore"></asp:ListItem>
                      <asp:ListItem Text="Loan Joint ID" Value="Mysore"></asp:ListItem>
                      <asp:ListItem Text="POA ID" Value="hubli"></asp:ListItem>
                      <asp:ListItem Text="Beneficiary ID" Value="hubli"></asp:ListItem>
                      <asp:ListItem Text="Member Photo ID" Value="hubli"></asp:ListItem>
                      <asp:ListItem Text="Select All" Value="All"></asp:ListItem>
                     </asp:CheckBoxList>
            </th>
            <th><br/><br/>
                <asp:Label ID="Label4" runat="server" Text="Statement"></asp:Label>
                <asp:CheckBoxList ID="StatementCheckBoxList" runat="server" tabindex="10" GroupName="receipts" CssClass="CheckBoxList">
                    <asp:ListItem Text="Account Statement" Value="Bangalore"></asp:ListItem>
                    <asp:ListItem Text="Credit Card Statement" Value="Mysore"></asp:ListItem>
                    <asp:ListItem Text="tax Statement" Value="Mysore"></asp:ListItem>
                    <asp:ListItem Text="Mortgage Statement" Value="hubli"></asp:ListItem>
                    <asp:ListItem Text="Select All" Value="All"></asp:ListItem>
                    </asp:CheckBoxList>
            </th>
            <th><br/>
                   <asp:Label ID="Label6" runat="server" Text="Receipts"></asp:Label>
                   <asp:CheckBoxList ID="ReceiptsCheckBoxList" runat="server" tabindex="11" GroupName="receipts" CssClass="CheckBoxList">
                   <asp:ListItem Text="Deposit Receipts" Value="Bangalore"></asp:ListItem>
                   <asp:ListItem Text="Withdrawal Receipts" Value="Mysore"></asp:ListItem>
                   <asp:ListItem Text="Select All" Value="All"></asp:ListItem>
                  </asp:CheckBoxList>
           </th>
           <th><br/>
                 <asp:Label ID="Label7" runat="server" Text="Wire Transfer"></asp:Label>
                 <asp:CheckBoxList ID="WireCheckBoxList" runat="server" tabindex="12" GroupName="receipts" CssClass="CheckBoxList">
                 <asp:ListItem Text="Outgoing Transfer" Value="Bangalore"></asp:ListItem>
                 <asp:ListItem Text="Incoming Transfer" Value="Mysore"></asp:ListItem>
                 <asp:ListItem Text="Select All" Value="All"></asp:ListItem>
               </asp:CheckBoxList>
           </th>
           <th><br/>
                <asp:Label ID="Label8" runat="server" Text="Signature Cards"></asp:Label>
                <asp:CheckBoxList ID="SignatureCheckBoxList" runat="server"  tabindex="13" GroupName="receipts" CssClass="CheckBoxList">
                <asp:ListItem Text="Signature Card" Value="Bangalore"></asp:ListItem>
                <asp:ListItem Text="Proxy form" Value="Mysore"></asp:ListItem>
                <asp:ListItem Text="Select All" Value="All"></asp:ListItem>
            </asp:CheckBoxList>
          </th>

       </tr>

       <tr>
         <th><br/><br/>
                <label for="textArea" class="col-sm-2 control-label">Comment*</label>
                <textarea  class="form-control" style="min-width: 100%; height: 82px; width:145px" id="textArea" placeholder="Your message"></textarea>
         </th>
      </tr>

      <tr>
         <th><br/><br/>
                <asp:Button ID="submit" runat="server" Text="Submit" CssClass="submit" OnClick="Button1_Click()" />

          </th>
        </tr>
    </table>  

</form>


        </div>
            <div id="footer">
                <label id="datetime" runat="server"> © <%= DateTime.Now.ToLongDateString() %></label>
            </div>
        </div>

<script>
    $('.CheckBoxList :checkbox[value=All]').click(function () {
        var toggle = this.checked;
        $(this).closest('.CheckBoxList').find(":checkbox").attr("checked", toggle);
    });
</script>


</body>