[DataGrid][整理]使用JavaScript+css+DataGrid實現Item的高亮顯示

來源:互聯網
上載者:User
1.設計好需要的樣式表,這個可以根據大家的喜好;我這裡就給個一般的。

<PRE>.button_down
{}{
    color: Red;
    border: inset 2px;
}

.button_up
{}{
    color: Black;
    border: outset 2px;
}

.alt_row_highlight
{}{
    background-color: Yellow;
}

.alt_row_nohighlight
{}{
    background-color: White;
}

.row_highlight
{}{
    background-color: Cyan;
}

.row_nohighlight
{}{
    background-color: White;
}
</PRE>

2.JavaScript:這裡主要借用Js在用戶端的良好表現,讓js動態改變DataGrid的Item的樣式,以此達到高亮顯示的效果。function classChange(styleChange,item) 
{
    item.className = styleChange;
}

3.最後的步驟就是,給DataGrid的Items添加js屬性private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
   if(e.Item.ItemType==ListItemType.Item)
   {
                   e.Item.Attributes.Add("onmouseover", "classChange('row_highlight',this);");
                    e.Item.Attributes.Add("onmouseout", "classChange('row_nohighlight',this);");
           }
}

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.