-1

我正在创建一个页面,该页面将在创建时动态地在页面上显示日志文件。这是我的前端:

                <div id="container">
                <asp:UpdatePanel UpdateMode="Conditional" runat="server"     ID="ServerUpdates"> 
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="Timer" />
                    </Triggers>
                </asp:UpdatePanel>
            </div>
        </div>

这是我的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;
}

这是我背后的代码:

        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>"));
    }

我的问题是它没有在第一个 Status div 旁边显示 URL div,所以第四个。URL div 最后显示。

我需要它在每个 div(文件)的 Status div 旁边显示 URL div。

我一直在尝试 GridView,所以任何建议都会有所帮助。

4

4 回答 4

1

我不确定我是否理解问题,但是对于您的问题“它没有在第一个 Status div 旁边显示 URL div,因此第四个。URL div 显示在最后”,我建议如下:

<div class="row">
  <div class="textboxStatus">
  </div>
  <div class="textboxURL">
  </div>
</div>

适用float: left;textboxStatustextboxURL。我知道,这是动态生成的,但是为什么不 AJAX 来获取内容然后简单地填充它呢?

您可以轻松地将 AJAX 与 Web 表单一起使用,如下所示:

http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

于 2013-04-25T16:31:11.813 回答
1

首先,我们将定义主 div 或主体,其中其他将包含该 div 样式将是

  #maindiv{
          width: 100%;
          font-size: 12px;
          overflow: hidden;
          background: #ccc
    }

在您的情况下,它将是“容器”

现在,当您将 div 添加为

那么第一个 div 样式将是

         #leftdiv {
                 float: left; 
                 width: 33%;
                 background-color: #bbb;
          }

之后设置每个 div 的宽度并将宽度设置为该 d 的样式

    #nextdiv { 
             float: left;
              background-color: #eee;
             width: 33%;
      }

等等..

于 2013-04-25T16:57:30.690 回答
1

在您的“.textboxStatus”css 类中,您定义了一个“float:left”并同时使用“clear:left”清除浮动。

删除这两个属性并在“.textboxURL”中将“float:right”替换为“float:left”,你应该没问题。

于 2013-04-25T16:48:28.403 回答
0

您应该生成一个<TABLE>包含一行<TR>和多列的控件,<td>而不是通过 Literal 控件生成 Asp.netGridview控件。

使用 Literal 控件时记得写 Html 标签

最终 html 示例:

<Table>
<tr>
<td>First div inside</td>
<td>Second div inside</td>
...
</tr>
</Table>
于 2013-04-25T16:40:21.133 回答