asp.net Gridview數(shù)據(jù)列中實現(xiàn)鼠標懸浮變色
更新時間:2010年06月11日 15:09:07 作者:
Gridview一般朋友們都比較常用,因為它可以方便快捷的實現(xiàn)我們所需的很多功能,代碼也比較簡潔。平時的項目中這個控件我也比較常用,其中有個功能用到的頻率也比較多。所以記錄下備忘。
功能描述:
在gridview中,鼠標在這個控件的數(shù)據(jù)列表中移動時,該列的背景隨鼠標的移動而改變背景顏色。
功能實現(xiàn):
在gridview中新增一個事件RowDataBound,代碼如下:
protected void gvwNews_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "color = this.style.backgroundColor;this.style.backgroundColor='#EAFCD5'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color");
e.Row.Attributes.Add("onclick", "ClickRow()");
}
}
其中的onclick事件是控制選擇行首的復選框的,點擊行便實現(xiàn)"點擊"復選框一樣的效果。代碼如下:
function ClickRow()
{
var obj = event.srcElement.parentElement.firstChild.firstChild.tagName;
alert(obj);
if(obj!=null && obj.tagName+""!="undefined")
{
obj.checked=obj.checked ? false : true;
}
}
簡單的幾行代碼所需功能就可以實現(xiàn)了。
在gridview中,鼠標在這個控件的數(shù)據(jù)列表中移動時,該列的背景隨鼠標的移動而改變背景顏色。
功能實現(xiàn):
在gridview中新增一個事件RowDataBound,代碼如下:
復制代碼 代碼如下:
protected void gvwNews_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "color = this.style.backgroundColor;this.style.backgroundColor='#EAFCD5'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color");
e.Row.Attributes.Add("onclick", "ClickRow()");
}
}
其中的onclick事件是控制選擇行首的復選框的,點擊行便實現(xiàn)"點擊"復選框一樣的效果。代碼如下:
復制代碼 代碼如下:
function ClickRow()
{
var obj = event.srcElement.parentElement.firstChild.firstChild.tagName;
alert(obj);
if(obj!=null && obj.tagName+""!="undefined")
{
obj.checked=obj.checked ? false : true;
}
}
簡單的幾行代碼所需功能就可以實現(xiàn)了。
您可能感興趣的文章:
- ASP.NET GridView控件在列上格式化時間及DataFormatString使用
- asp.net DataFormatString格式化GridView
- ASP.NET數(shù)據(jù)綁定GridView控件使用技巧
- ASP.NET數(shù)據(jù)綁定之GridView控件
- 利用jQuery及AJAX技術定時更新GridView的某一列數(shù)據(jù)
- asp.net中GridView數(shù)據(jù)鼠標移入顯示提示信息
- DevExpress實現(xiàn)GridView當無數(shù)據(jù)行時提示消息
- asp.net讀取excel中的數(shù)據(jù)并綁定在gridview
- 使用ajax局部刷新gridview進行數(shù)據(jù)綁定示例
- c#利用Excel直接讀取數(shù)據(jù)到DataGridView
- js獲取GridView中行數(shù)據(jù)的兩種方法 分享
- C#與SQL連接:GridView控件對數(shù)據(jù)庫的操作
- Gridview利用DataFormatString屬性設置數(shù)據(jù)格式的方法
相關文章
WPF實現(xiàn)ScrollViewer滾動到指定控件處
這篇文章主要為大家詳細介紹了WPF實現(xiàn)ScrollViewer滾動到指定控件處,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06ASP.NET中RadioButtonList綁定后臺數(shù)據(jù)后觸發(fā)點擊事件
這篇文章主要介紹了ASP.NET中RadioButtonList綁定后臺數(shù)據(jù)后觸發(fā)點擊事件的相關資料,感興趣的小伙伴們可以參考一下2016-05-05ASP.NET MVC 數(shù)據(jù)驗證及相關內容
這篇文章主要介紹了ASP.NET MVC 數(shù)據(jù)驗證及相關內容的相關資料,需要的朋友可以參考下2014-10-10