![](/img/trans.png)
[英]ASP.NET Gridview: Highlighting rows on mouse over then updating the highlighted rows
[英]Mouse over highlighting of dates in ASP.NET calender
我正在嘗試將鼠標移到ASP.NET中的默認日歷上來更改顏色。 到目前為止,我已經嘗試實現以下代碼:
Color col = new Color();
col = Calendar1.DayStyle.BackColor;
if (col != Color.Empty)
{
e.Cell.Attributes["onmouseover"] = "this.style.backgroundColor='pink';";
e.Cell.Attributes["onmouseout"] = "this.style.backgroundColor='" + col + "';";
}
else
{
e.Cell.Attributes["onmouseover"] = "this.style.backgroundColor='pink';";
e.Cell.Attributes["onmouseout"] = "this.style.backgroundColor='';";
}
如果我不單擊日期,則似乎一切正常。 但是,當我單擊日期並將日期背景更改為灰色時,背景顏色更改為粉紅色,然后再次更改為白色。 這似乎是因為以某種方式
col = Calendar1.DayStyle.BackColor;
沒有選擇正確的背景色?
我在這里想念什么嗎?
為什么不以編程方式這樣做:
Color col = new Color();
col = (e.IsSelected) ? Calendar1.SelectedDayStyle.BackColor.ToString() : Calendar1.DayStyle.BackColor.ToString();
e.Cell.Attributes["onmouseover"] = "this.style.backgroundColor='pink';";
e.Cell.Attributes["onmouseout"] = "this.style.backgroundColor='" + col + "';";
您需要確定是否已選擇當前日期進行渲染。 我不確定是否有IsSelected屬性。 如果沒有,則用執行此操作的東西替換e.IsSelected。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.