如何使用数据创建动态div

pw136qt2  于 2021-08-09  发布在  Java
关注(0)|答案(1)|浏览(261)

我正在使用内部html来动态获取带有sqlserver数据的div。div排列没有水平对齐。需要将它们水平对齐。请帮帮我。谢谢

pnl_default.Visible = true;
        pnl_content.Visible = false;
        HtmlGenericControl html_default = new HtmlGenericControl();
        html_default.TagName = "div";

        string cmdString = ".........";

        DataTable dtSystems = OraQueryData(cmdString);
        foreach (DataRow dtRow in dtSystems.Rows)
        {
            string system_name = Convert.ToString(dtRow["Branch"]);

            var btn_system = new Button
            {
                ID = "btn_" + system_name,
                Text = system_name,

                CssClass = "myButton2"
            };

            string html = " <div class=div1> <div class= pnlback >  <div class= header> <b>" + system_name + " </b></div><div class= body> <img style= width: '50px'; height: 50px src =/Scripts/atm.png> </div><div class=footer><button  runat=server>SHOW</i></button></div></div> </ div >   <span></ span >   ";

            html_default.Controls.Add(new LiteralControl(html));
            html_default.Controls.Add(new LiteralControl("<p>"));               

        }
        Panel2.Controls.Clear();
        Panel2.Controls.Add(html_default);


我需要做的是。。

这几位是不可数的。。。我需要从主管那里得到填充板。

5jdjgkvh

5jdjgkvh1#

lulitha,测试这些代码并在你的div中使用:

<style type="text/css">
    #dad{text-align: center;width: 100%;}
       .son{display: inline-block;padding: 0px 5px;border: 1px solid;margin:0 5px;}
</style>
<div id="dad">
    <div class="son">son</div>
    <div class="son">son</div>
    <div class="son">son</div>
    <div class="son">son</div>
    <div class="son">son</div>
</div>

<br />

<div id="dad">
    <div class="son">son</div>
    <div class="son">son</div>
    <div class="son">son</div>
    <div class="son">son</div>
</div>

<br />

<div id="dad">
    <div class="son">son</div>
    <div class="son">son</div>
    <div class="son">son</div>
</div>

相关问题