如何解决如何使用stringbuilder的按钮制作模态模块?
我尝试使用引导程序制作一个模态,该模态应该包含各种信息,例如数据库中的label5,具体取决于您按下的按钮。我希望按钮是使用stringbuilder自动生成的。我想使用@MachineID作为我的sql select的参数。有什么办法吗?我已经测试了几种不同的方法,但是没有找到解决方案。
在这里我的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); /* Fallback color */
background-color: rgba(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",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);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。