隐藏动态div标签,包含动态输入按钮

时间:2012-05-14 15:52:36

标签: c# asp.net css

我在C#(Asp.net)中的标签内动态创建一个div标签,它将包含3个动态生成的按钮。我只希望当用户将鼠标放在表格单元格(td标签)上时显示div。我可以通过.css实现这一点吗?

C#中的动态生成如下所示:

HtmlTableCell cell = (HtmlTableCell)c;

                        HtmlInputButton PopupAddButton = new HtmlInputButton();
                        PopupAddButton.ID = "PBA" + c.ID.ToString();
                        PopupAddButton.Value = "Add";
                        PopupAddButton.Style["Height"] = "14px";
                        PopupAddButton.Style["Width"] = "40px";
                        PopupAddButton.Style.Add(HtmlTextWriterStyle.Top, "-100");
                        PopupAddButton.Style["right"] = "0";
                        PopupAddButton.Style["float"] = "left";
                        PopupAddButton.Style["vertical-align"] = "top";
                        PopupAddButton.Style["font-size"] = "9px";

                        HtmlInputButton PopupEditButton = new HtmlInputButton();
                        PopupEditButton.ID = "PBE" + c.ID.ToString();
                        PopupEditButton.Value = "Edit";
                        PopupEditButton.Style["Height"] = "14px";
                        PopupEditButton.Style["Width"] = "40px";
                        PopupEditButton.Style["top"] = "0";
                        PopupEditButton.Style["right"] = "0";
                        PopupEditButton.Style["float"] = "left";
                        PopupEditButton.Style["vertical-align"] = "top";
                        PopupEditButton.Style["font-size"] = "9px";

                        HtmlInputButton PopupDeleteButton = new HtmlInputButton();
                        PopupDeleteButton.ID = "PBD" + c.ID.ToString();
                        PopupDeleteButton.Value = "Delete";
                        PopupDeleteButton.Style["Height"] = "14px";
                        PopupDeleteButton.Style["Width"] = "40px";
                        PopupDeleteButton.Style["top"] = "0";
                        PopupDeleteButton.Style["right"] = "0";
                        PopupDeleteButton.Style["float"] = "left";
                        PopupDeleteButton.Style["font-size"] = "9px";
                        PopupDeleteButton.Style.Add(HtmlTextWriterStyle.VerticalAlign, "top");


                        PopupAddButton.Attributes.Add("onClick", "AddPopupControlToTableCell('" + cell.ClientID + "', '" + cell.Height.ToString() + "', '" + g_PopupControlId + "');");
                        PopupEditButton.Attributes.Add("onClick", "EditPopupControlToTableCell('" + cell.ClientID + "', '" + cell.Height.ToString() + "', '" + g_PopupControlId + "');");
                        PopupDeleteButton.Attributes.Add("onClick", "DeletePopupControlToTableCell('" + cell.ClientID + "', '" + cell.Height.ToString() + "', '" + g_PopupControlId + "');");

                        HtmlGenericControl ButtonDiv = new HtmlGenericControl("div");
                        ButtonDiv.ID = "buttonBlock" + c.ID.ToString();
                        ButtonDiv.Attributes.Add("class", "buttonBlock");

                        ButtonDiv.Controls.Add(PopupAddButton);
                        ButtonDiv.Controls.Add(PopupEditButton);
                        ButtonDiv.Controls.Add(PopupDeleteButton);

                        cell.Controls.Add(ButtonDiv);

我的.css目前看起来像这样

.buttonBlock input{
  display:none;
}
td:hover #buttonBlock input{
 display:inline;
}

然而,这不起作用。我做错了什么?

1 个答案:

答案 0 :(得分:0)

首先尝试修复此代码

td:hover #buttonBlock input{
display:inline;
}

td:hover .buttonBlock input{
display:inline;}

你的原文正在寻找一个buttonBlock(#buttonBlock)的id,当它应该找一个buttonBlock类(.buttonBlock