【发布时间】:2010-11-04 14:05:15
【问题描述】:
这是对我之前的问题的跟进: link text
在 gridview 的列中,我有一个链接按钮和一个标签。
我想在点击链接按钮时隐藏/取消隐藏标签。我使用 javascript 因为我不想要任何回发。 代码:
protected void gvwComments_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lButton = ((LinkButton)e.Row.Cells[2].FindControl("lbtnExpand"));
Label label = ((Label)e.Row.Cells[2].FindControl("lblBody"));
lButton.Attributes.Add("onclick", string.Format("HideLabel('{0}'); return false;", label.ClientID));
}
}
function HideLabel(button) {
var rowObj = document.getElementById(button);
if (rowObj.style.display == "none") {
rowObj.style.display = "block";
}
else {
rowObj.style.display = "none";
}
}
问题是,当我通过单击按钮取消隐藏标签时,链接按钮会稍微向上移动它在单元格中的原始位置。 是否可以在 gridviews 单元格中保留链接按钮的位置?
【问题讨论】:
标签: c# asp.net javascript css