简体   繁体   English

将引导程序代码与.aspx.cs文件链接

[英]Linking bootstrap Code with .aspx.cs file

Can anyone tell me how to link my code written in bootstrap 3.1.1 with the code in my aspx.cs file. 谁能告诉我如何将引导程序3.1.1中编写的代码与aspx.cs文件中的代码链接。 What I basically want to do is to to access the different elements(of bootstrap design) in .aspx.cs file using their ID's. 我基本上想要做的是使用ID来访问.aspx.cs文件中的不同元素(引导设计)。

For example, I have this html code: 例如,我有以下html代码:

 <div class="panel panel-success" style="margin-top:100px;margin-left:50px">
        <div class="panel-heading" style="font-size:16px">   To-Do List </div>
        <ol class="list=group" id="list1">
                <li class="list-group-item"> Complete HCI Assignment </li>
                <li class="list-group-item"> Complete BE Assignment </li>
                <li class="list-group-item"> Complete Programming Task </li>
                <li class="list-group-item"> Send Code Correction </li>
        </ol>
        <div class="panel-body">
            <button class="btn btn-default btn-success btn-sm" style="margin-left:65px;
              margin-right:10px" id="b1">
                <span class="glyphicon glyphicon-plus"></span> Add Task
            </button>
            <button class="btn btn-default btn-success btn-sm" id="b2"> 
             <span class="glyphicon glyphicon-remove"></span> Remove Task
            </button>
       </div>
    </div> 

I want to display data from my database (SQL Server) in this panel. 我想在此面板中显示数据库(SQL Server)中的数据。 How do I do this? 我该怎么做呢?

In order for you access the HTML controls in the code behind file, you need to use ASP.NET server controls. 为了访问文件后面代码中的HTML控件,您需要使用ASP.NET服务器控件。 To retrofit an existing web page you need to enclose all server controls with a form tag with a runat="server" attribute. 要改造现有的网页,您需要使用带有runat =“ server”属性的表单标签将所有服务器控件括起来。 You can then add server controls anywhere inside the form, such as the label with the ID "ServerControl" shown below. 然后,您可以在表单内的任何位置添加服务器控件,例如下面显示的ID为“ ServerControl”的标签。 Be aware that only one form with runat="server" attribute can exist on a web page. 请注意,网页上只能存在一种具有runat =“ server”属性的表单。

<form runat="server">
<div class="panel panel-success" style="margin-top:100px;margin-left:50px">
    <div class="panel-heading" style="font-size:16px">   To-Do List </div>
    <ol class="list=group" id="list1">
        <% foreach(var task in tasks) { %>
            <li class="list-group-item"> <%=task.name&> </li>
        <% } %>
    </ol>
    <asp:Label runat="server" ID="ServerControl" Text="results" />
    <div class="panel-body">
        <button class="btn btn-default btn-success btn-sm" style="margin-left:65px;
          margin-right:10px" id="b1">
            <span class="glyphicon glyphicon-plus"></span> Add Task
        </button>
        <button class="btn btn-default btn-success btn-sm" id="b2"> 
         <span class="glyphicon glyphicon-remove"></span> Remove Task
        </button>
   </div>
</div>
</form>

http://www.w3schools.com/aspnet/aspnet_controls.asp http://www.w3schools.com/aspnet/aspnet_controls.asp

You code can perform the SQL queries and update the server controls on the web page. 您的代码可以执行SQL查询并更新网页上的服务器控件。 I've added C# markup that will output a list from a collection of 'tasks'. 我添加了C#标记,该标记将从“任务”的集合中输出列表。 The collection would be populated from SQL during the loading of the web form. 在加载Web表单期间,将从SQL填充该集合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM