[英]How to display a dynamically created DIV next to another?
I am creating a page that will display log files on a page dynamically as they are created. 我正在创建一个页面,该页面将在创建日志文件时在其上动态显示日志文件。 Here is my front end: 这是我的前端:
<div id="container">
<asp:UpdatePanel UpdateMode="Conditional" runat="server" ID="ServerUpdates">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
Here is my css: 这是我的CSS:
#container {
width:100%;
display: inline-block;
height:100%;
}
.textboxStatus
{
/*background-image:url('http://placehold.it/15/15');*/
background-repeat:no-repeat;
/* background-position:3px 3px;*/
border:solid 1px black;
padding:20px;
width:600px;
height:500px;
float:left;
clear:left;
/*position:relative;*/
}
/*.textbox input
{
border:none;
background:transparent;
width:100%;
outline: none;
}*/
.textboxURL
{
/*background-image:url('http://placehold.it/15/15');*/
background-repeat:no-repeat;
/* background-position:3px 3px;*/
border:solid 1px black;
padding:20px;
width:575px;
height:475px;
float:right;
/*clear: right;
position:relative;*/
display:inline;
}
Here is my code behind: 这是我的代码背后:
protected void CreateDiv(object sender, EventArgs e)
{
string path = @"\\server\d$\websites\Updates\Product\Production\Logs";
//int rowCount = 0;
DirectoryInfo dir = new DirectoryInfo(path);
List<FileInfo> FileList = dir.GetFiles().ToList();
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("<asp:GridView runat='server' ID='Grid' AutoGenerateColumns='false'>"));
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("<Columns>"));
foreach (FileInfo file in FileList)
{
StreamReader sr = new StreamReader(new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
// string[] findStatus = System.IO.Directory.Exists(path, "codepush.log.*", System.IO.SearchOption.TopDirectoryOnly);
// string[] findURL = System.IO.Directory.GetFiles(path, "sql.output.log.*", System.IO.SearchOption.TopDirectoryOnly);
bool findStatus = (file.Name.Contains("codepush.log.")) ? true : false;//File.Exists(Path.Combine(path, ".txt"));
bool findURL = (file.Name.Contains("sql.output.")) ? true : false;
if (findStatus == true)
{
//ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<br /><div class=\"statusLog\"><asp:TextBox runat=\"server\" id=\"tbStatus{0}\"/> </div><div class=\"urlLog\"></div>", count)));
//(TextBox)ServerUpdates.ContentTemplateContainer.FindControl("tbStatus" + count.ToString());
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<asp:BoundField Datafield={0} /><div class='textboxStatus'>", rowCount)));
TextBox txt = new TextBox();
txt.TextMode = TextBoxMode.MultiLine;
txt.Wrap = false;
txt.Width = 600;
txt.Height = 500;
while (!sr.EndOfStream)
txt.Text = txt.Text + sr.ReadLine() + "\r\n";
//Panel txt = new Panel();
//txt.ScrollBars = ScrollBars.Vertical;
//txt.Wrap = true;
ServerUpdates.ContentTemplateContainer.Controls.Add(txt);
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("</Columns>"));
}
if (findURL == true)
{
//ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<br /><div class=\"statusLog\"><asp:TextBox runat=\"server\" id=\"tbStatus{0}\"/> </div><div class=\"urlLog\"></div>", count)));
//(TextBox)ServerUpdates.ContentTemplateContainer.FindControl("tbStatus" + count.ToString());
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("<Columns>"));
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl(string.Format("<asp:BoundField Datafield={0} /><div class='textboxURL'>", rowCount)));
TextBox txt = new TextBox();
txt.TextMode = TextBoxMode.MultiLine;
txt.Wrap = false;
txt.Width = 575;
txt.Height = 475;
while (!sr.EndOfStream)
txt.Text = txt.Text + sr.ReadLine() + "\r\n";
//Panel txt = new Panel();
//txt.ScrollBars = ScrollBars.Vertical;
//txt.Wrap = true;
ServerUpdates.ContentTemplateContainer.Controls.Add(txt);
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("</Columns>"));
}
//rowCount++;
}
ServerUpdates.ContentTemplateContainer.Controls.Add(new LiteralControl("</asp:GridView>"));
}
My issue is that it is not displaying the URL div next to the first Status div and so fourth. 我的问题是,它没有在第一个Status div旁边显示URL div,所以在第四个显示旁边。 The URL div displays last. URL div最后显示。
I need it to display the URL div next to the Status div for each div (file). 我需要它在每个div(文件)的Status div旁边显示URL div。
I have been trying GridView so any suggestions would be helpful. 我一直在尝试GridView,所以任何建议都会有所帮助。
I am not sure I understand the problem, but to your issue " it is not displaying the URL div next to the first Status div and so fourth. The URL div displays last," I recommend the following: 我不确定我是否理解问题,但是对于您的问题,“它没有在第一个Status div旁边显示URL div,因此在第四个Status div旁边显示。URLdiv显示最后一个”,我建议以下做法:
<div class="row">
<div class="textboxStatus">
</div>
<div class="textboxURL">
</div>
</div>
Apply float: left;
套用float: left;
to both textboxStatus
and textboxURL
. 到textboxStatus
和textboxURL
。 I understand, this is dynamically generated, but instead, why not AJAX to fetch the content and then simply fill it? 我知道,这是动态生成的,但是,为什么不使用AJAX来获取内容然后简单地填充它呢?
You can easily use AJAX with webforms like so: 您可以轻松地将AJAX与Webform一起使用,如下所示:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/ http://encosia.com/using-jquery-to-direct-call-aspnet-ajax-page-methods/
In your ".textboxStatus" css-class you have defined a "float:left" and are clearing the float at the same time with "clear:left". 在“ .textboxStatus” css类中,您定义了“ float:left”,并使用“ clear:left”同时清除了浮点数。
Remove both attributes and in ".textboxURL" replace "float:right" with "float:left" and you should be fine. 删除这两个属性,并在“ .textboxURL”中将“ float:right”替换为“ float:left”,就可以了。
first we will define the main div or body in which other will be contained for that div the style will be 首先,我们将定义主div或主体,该div将包含其他主体或样式,样式将为
#maindiv{
width: 100%;
font-size: 12px;
overflow: hidden;
background: #ccc
}
in your case it will be "container" 在您的情况下,它将是“容器”
now when you are adding the divs as 现在,当您将div添加为
then first div style will be 那么第一个div样式将是
#leftdiv {
float: left;
width: 33%;
background-color: #bbb;
}
after that set the width of each div and put the width to the style of that d 之后,设置每个div的宽度,并将宽度设置为d的样式
#nextdiv {
float: left;
background-color: #eee;
width: 33%;
}
and so on.. 等等..
You should generate a <TABLE>
with one line <TR>
and multiple columns <td>
instead of generating an Asp.net Gridview
control by Literal controls. 您应该生成具有一行<TR>
和多列<td>
的<TABLE>
,而不是通过文字控件生成Asp.net Gridview
控件。
Remember to write Html tags when you use Literal controls 使用文字控件时,请记住要编写HTML标签
Example of final html: 最终html的示例:
<Table>
<tr>
<td>First div inside</td>
<td>Second div inside</td>
...
</tr>
</Table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.