0

押すボタンに応じて、データベースからの label5 などのさまざまな情報を含むブートストラップを使用してモーダルを作成しようとしています。ボタンをstringbuilderで自動生成したい。SQL select のパラメーターとして @MachineID を使用したいと考えています。それを行う方法はありますか?いくつかの異なる方法をテストしましたが、解決策は見つかりませんでした。

ここに私のHTMLがあります

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Dashboard.aspx.cs" Inherits="TSG_Maskinintergration.Dashboard" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style>
        label {
            color: #fff;
        }

         /* The Modal (background) */
            .modal {
              display: none; /* Hidden by default */
              position: fixed; /* Stay in place */
              z-index: 1; /* Sit on top */
              left: 0;
              top: 0;
              width: 100%; /* Full width */
              height: 100%; /* Full height */
              overflow: auto; /* Enable scroll if needed */
              background-color: rgb(0,0,0); /* Fallback color */
              background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
              
            }

            /* Modal Content/Box */
            .modal-content {
              background-color: #fefefe;
              margin: 15% auto; /* 15% from the top and centered */
              padding: 20px;
              border: 1px solid #888;
              width: 80%; /* Could be more or less, depending on screen size */
              border-radius:15px;
            }

        
    </style>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        function openModal() {
            $('#myModal').modal('show');
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder" runat="server">
    <h2>Welcome <asp:Label ID="lblFirstName" runat="server" ForeColor="White"></asp:Label> <asp:Label ID="lblLastName" runat="server" ForeColor="White"></asp:Label></h2>
    <br />
    <asp:PlaceHolder ID="MachineBoxHolder" runat="server"></asp:PlaceHolder>
    <asp:Button ID="btnLogout" runat="server" Text="Logout" OnClick="btnLogout_Click" />
        
    

    <h2>modal</h2>

        <asp:Button ID='Button1' runat='server' Text='Button' OnClick='Button1_Click' />
        <br />
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
            aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                    </div>
                    <div class="modal-body">
                        something
                        <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
                    </div>
                    <div class="modal-footer">
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal -->
        </div>
        
</asp:Content>

これが私のcです

public partial class Dashboard : System.Web.UI.Page
    {
        public static Databas db = new Databas(); //Class Databas
        public string email;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Response.Redirect("Login.aspx");
            }

            db.SqlOpenConnection(***);

            DataTable UserInfo = db.SqlReadTablePara("GetUserInfo", "@UserID", Convert.ToString(Session["UserID"]));

            foreach (DataRow row in UserInfo.Rows)
            {
                lblFirstName.Text = row["Firstname"].ToString();
                lblLastName.Text = row["LastName"].ToString();
                Session["AccessLevel"] = row["AccessLevel"].ToString();
            }

            
            DataTable UserMachines = db.SqlReadTablePara("GetUserMachines", "@UserID", Convert.ToString(Session["UserID"]));

            StringBuilder html = new StringBuilder();

            foreach (DataRow row in UserMachines.Rows)
            {
                string MachineID = row["MachineID"].ToString();

                DataTable TempMachine = db.SqlReadTablePara("GetMachineStatus", "@MachineID", MachineID);

                foreach (DataRow row1 in TempMachine.Rows)

                {
                    html.Append("<div class='machinebox' style='Background-Color: #fff;'>");
                    if (row1.Field<Int32>("effectively") < 10) {
                        html.Append("<div class='status' style='Background-Color: Red; height:10px; width=10px;'>");
                    }
                    else
                    {
                        html.Append("<div class='status' style='Background-Color: Green; height:10px; width=10px;'>");
                    }
                    html.Append("</div>");
                    html.Append("<p>Machinenumber: " + row["MachineNumber"].ToString() + "</p>");
                    html.Append("<p>Machinname: " + row["MachineName"].ToString() + "</p>");
                    html.Append("<p>Availability: " + row1["Availability"].ToString() + "%</p>");
                    html.Append("<p>Counter: " + row1["Counter"].ToString() + "st</p>");
                    html.Append("<p>From time: " + row["Availabilitytime"].ToString() + "</p>");
                    html.Append("<Button ID='Button1' runat='server' Text='Button' OnClick='Button1_Click' />");
                    html.Append("</div>");

                }

                }


            //GridView1.DataSource = UserMachines;
            //GridView1.DataBind();

            MachineBoxHolder.Controls.Add(new Literal { Text = html.ToString() });

            db.SqlCloseConnection();

        }

        protected void btnLogout_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect("Login.aspx");
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            Label5.Text = "Test";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
        }
    }
4

0 に答える 0