如何在c#中多次显示相同的div ... [英] How do I show the same div multiple times in c#...

查看:62
本文介绍了如何在c#中多次显示相同的div ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我在html标记中创建的div。这个div具有我想要保留的特定样式。但现在,我想从数据库(SQL Server)读取数据。数据库中的每一行都将显示在其自己的div中,但具有相同的样式。



我正在使用C#

I have a div that I created in html markup. This div has specific styling that I want to keep. But now, I want to read data from the database (SQL Server). Each row from the database will be shown in its "own div", BUT with the same styling.

I am using C#

推荐答案

有了这些小信息,我只能说你可以在.aspx页面中迭代一个循环并多次显示div。



示例,

With this little information I could only say that you can iterate a loop in .aspx page and display the divs that many times.

Example,
<% for (int i=0; i<5; i++) 
{%>
    <div class="some-class">
    <!-- content that you want to display -->
    </div>
<% } 
%>



将循环迭代限制更改为您获得的记录数,然后您就可以开始了。



希望这会有所帮助。



-KR


Change the loop iteration limit to the number of records you're getting and then you're good to go.

Hope this helps.

-KR


对不起没有提供足够的信息,



在页面加载我有这个代码。



Sorry for not giving enough info,

On the Page Load I have this code.

protected void Page_Load(object sender, EventArgs e)
        {

            if (!this.IsPostBack)
            {

                BusinessLayer bl = new BusinessLayer();
                DataSet ds = new DataSet();

                ds = bl.GetAllActivities();
                //grvActivities.DataSource = ds;
                //grvActivities.DataBind();
 

                foreach  (DataTable table in ds.Tables)
                {
                    string activityName;
                    string descrpttion;
                    int point;
                    
                   
                  //  System.Web.UI.HtmlControls.HtmlGenericControl DivAdder = new System.Web.UI.HtmlControls.HtmlGenericControl();
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        
                          
                        DataRow row = table.Rows[i];
                        activityName = row["activityName"].ToString();
                        descrpttion = row["ActivityDesc"].ToString();
                        point = Convert.ToInt16(row["points"]); 

                        

                       

                        lblName.Text = activityName.ToString();
                        lblDesc.Text = descrpttion;
                        lblPoints.Text = point.ToString();
                        divAccordion.Visible = true;
                        
                    }















然后在Html方面我有这个div。














then on the Html side i have this div.



<div class="content" style="width:400px;">

              <div class="module-head" style="width:700px;">
                  <h4><b>Core Training</b></h4>

                   <a  type="button" href="#pnlModal" class="btn btn-primary btn-sm" data-toggle="modal" style="float:right">New
                       <i class="glyphicon glyphicon-plus "></i>
                   </a><br />

              </div>
          <br />
           <div class="module-body">

          <div class="container" style="width:700px">
              <div class="panel-group" id="divAccordion" runat="server">
              <div class="panel panel-primary">

              <div class="panel-heading">
                  <div class="panel-title" runat="server">
                      <asp:LinkButton runat="server" ID="lblName" Font-Size="Medium"></asp:LinkButton>
                  </div>
              </div>

               <div class="panel-body">

                   <asp:Label runat="server" ID="lblDesc"></asp:Label>

                   <br />
                   <br />
                 <p>
                     <b> <asp:Label runat="server" ID="Label1" Text="Points"></asp:Label> </b>
                     <b> <asp:Label runat="server" ID="lblPoints"></asp:Label></b>
                 </p>
               </div>:

              </div>

        </div>

       </div>






这篇关于如何在c#中多次显示相同的div ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆