我正在开发一个充当博客的网站。我的问题在于评论部分,它涉及儿童评论小组的调整。我尝试添加CSS以使面板浮动,但它们保持在左侧。我也尝试将父面板的HorizontalAlign设置为右边。
有关更多上下文,这是评论部分的图像:
As you can see, the child comments panels are sticking to the left.
这是我将注释部分动态创建到名为Panel1的现有面板的方法。
protected void drawComments(string ID, int NumTabs, Panel parentPanel) {
string hash = ID;
SqlConnection conn = new SqlConnection(Secret Stuff);
string cmdStr = "SELECT * FROM Comments WHERE ParentID=@searchHash";
SqlCommand cmd = new SqlCommand(cmdStr, conn);
cmd.Parameters.Add("@searchHash", SqlDbType.NVarChar).Value = hash;
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
Panel tempPanel;
if (reader.HasRows)
{
while (reader.Read())
{
ID = reader.GetString(4);
tempPanel = new Panel();
tempPanel.BorderStyle = BorderStyle.Solid;
tempPanel.BorderColor = System.Drawing.ColorTranslator.FromHtml("#2461bf");
tempPanel.Width = new Unit((100 - (NumTabs * 5)).ToString() + "%");
tempPanel.Attributes.Add("style", "margin-left:auto;");
tempPanel.Attributes.Add("style", "margin-right:auto;");
if (NumTabs > 0)
{
tempPanel.Attributes.Add("style", "margin-bottom:5px");
// tempPanel.Attributes.Add("style", "border-top-style:none");
tempPanel.Attributes.Add("style", "border-left-style:none");
// tempPanel.Attributes.Add("style", "border-right-style:solid");
tempPanel.Attributes.Add("style", "border-bottom-style:none");
}
else
{
tempPanel.Attributes.Add("style", "margin-top:50px");
// Panel1.Controls.Add(new LiteralControl("<BR />"));
}
Label currComment = new Label();
Label currAuthor = new Label();
currComment.Text = reader.GetString(0);
currAuthor.Text = reader.GetString(3).Split('@')[0];
Table tbl = new Table();
tbl.Width = new Unit("100%");
tbl.Attributes.Add("style", "margin-left:auto");
tbl.Attributes.Add("style", "margin-right:auto");
TableRow tblrow1 = new TableRow();
TableCell tblcell11 = new TableCell();
TableCell tblcell12 = new TableCell();
tblcell11.HorizontalAlign = HorizontalAlign.Right;
tblcell11.Width = new Unit("30%");
tblcell11.Text = currAuthor.Text + " Says:";
tblcell12.HorizontalAlign = HorizontalAlign.Left;
tblcell12.Text = currComment.Text;
tblcell12.Width = new Unit("70%");
tblrow1.Cells.Add(tblcell11);
tblrow1.Cells.Add(tblcell12);
tbl.Rows.Add(tblrow1);
TableCell tblcell21 = new TableCell();
tblcell21.Width = new Unit("30%");
ImageButton replyButton = new ImageButton();
replyButton.ImageUrl = "~/images/replybutton.png";
replyButton.Attributes.Add("style", "float:right");
replyButton.Width = 77;
replyButton.ID = ID;
replyButton.Command += addReply;
ImageButton likeButton = new ImageButton();
likeButton.ImageUrl = "~/images/likebutton.png";
likeButton.Attributes.Add("style", "float:right");
likeButton.Width = 65;
Label likeCount = new Label();
likeCount.Attributes.Add("style", "float:right");
likeCount.BorderStyle = BorderStyle.Groove;
likeCount.Text = "0";
TableCell tblcell22 = new TableCell();
tblcell22.HorizontalAlign = HorizontalAlign.Left;
tblcell22.Controls.Add(likeCount);
tblcell22.Controls.Add(likeButton);
tblcell22.Controls.Add(replyButton);
tblcell22.Width = new Unit("70%");
TableRow tblrow2 = new TableRow();
tblrow2.Cells.Add(tblcell21);
tblrow2.Cells.Add(tblcell22);
tbl.Rows.Add(tblrow2);
tempPanel.Controls.Add(tbl);
//tempPanel.Controls.Add(currComment);
if (NumTabs>0)
{
parentPanel.Controls.Add(tempPanel);
}
else
Panel1.Controls.Add(tempPanel);
drawComments(reader.GetString(4), NumTabs + 1, tempPanel);
}
}
}
catch (Exception ex)
{
lblDebug.Text = ex.ToString();
}
finally { conn.Close(); }
}
任何建议让这些儿童面板正确对齐将不胜感激。我希望你能通过这个写得不好的15岁的代码来理解我的目标。