0

Начну с описания задачи. На странице есть два checkBox, один DropDownlist один ListBox и две кнопки. В зависимости от вибора checkBox-са меняются значения в DropDownlist-те. При нажатии кнопки Добавить значения из DropDownlist добавляются в ListBox. Как реализовать что бы при нажатии кнопки Создать даные отправлялись на сервер и создавались например таблици с названиями которые были в ListBox.

Мой код (простой для примера ) :

HTML :

<form id="form1" runat="server">
        <div>
            <asp:CheckBox ID="NumberType" runat="server" Text="Числа типы " OnClick ="NumberTypeChecked()" />
            <br />
            <asp:CheckBox ID="WorkWithCurrency" runat="server" Text="Тип для роботи с валютою" OnClick="WorkWithCurrencyChecked()" />
            <br />
            <asp:DropDownList ID="DropDownListTypeColums" runat="server" Width="200px" ></asp:DropDownList>
            <br />
            <asp:ListBox ID="NameColums" runat="server"  Width="300px" Height="100px"></asp:ListBox>
            <br />
            <asp:Button ID="AddInformColums" runat="server" Text="Добавить" OnClientClick="AddInformColums_Click()"/>
            <asp:Label ID="Error" runat="server"></asp:Label>
            <asp:Button ID="AddDB" runat="server" Text="Создать" />
        </div>
    </form>

JS:

function AddInformColums_Click() {
            event.preventDefault();
            let name = document.getElementById("DropDownListTypeColums").value;
            if (name == "") {
                let Error = document.getElementById("Error");
                Error.textContent = "Error";
            } else {
                let Error = document.getElementById("Error");
                Error.textContent = "";
                let NameElement = document.getElementById("NameColums");
                let option = document.createElement("option");
                option.text = name;
                NameElement.add(option)
            }
        }

        function NumberTypeChecked() {
            let NumberType = document.getElementById("NumberType");
            let WorkWithCurrency = document.getElementById("WorkWithCurrency");
            
        
            if (NumberType.checked) {
                let DropDownListTypeColums = document.getElementById("DropDownListTypeColums");
        
                DropDownListTypeColums.innerHTML = "";
        
                let ArrayValues = [
                    "serial",
                    "smallserial"
                ];
        
                for (let i = 0; i < ArrayValues.length; i++) {
                    var option = document.createElement("option");
                    option.text = ArrayValues[i];
                    option.value = ArrayValues[i];
                    DropDownListTypeColums.appendChild(option);
                }
        
                WorkWithCurrency.checked = false;
            }
        }
        
        function WorkWithCurrencyChecked() {
            let NumberType = document.getElementById("NumberType");
            let WorkWithCurrency = document.getElementById("WorkWithCurrency");
            
        
            if (WorkWithCurrency.checked) {
                
        
                DropDownListTypeColums.innerHTML = "";
        
                let ArrayValues = [
                    "money"
                ];
        
                for (let i = 0; i < ArrayValues.length; i++) {
                    var option = document.createElement("option");
                    option.text = ArrayValues[i];
                    option.value = ArrayValues[i];
                    DropDownListTypeColums.appendChild(option);
                }
                NumberType.checked = false;
                
            }
        }

Желательно если можно реализовать это в файле WebForm.cs. Он у меня имеет вид :

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class LoginPasswordUser : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
    }
}

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Посмотрите другие вопросы с метками или задайте свой вопрос.