《影》

XMSHADOW'S BLOG
DATAGRID控件技巧 (1)

 鼠标悬停效果

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
     
{
            
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
    
{
                e.Item.Attributes.Add(
"onmousemove","c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
                e.Item.Attributes.Add(
"onmouseout","this.style.backgroundColor='#5544ff'");
              }

        }



排序代码
private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
  
{
     
if(ViewState["order"]==null)
    
{
           ViewState[
"order"]="ASC";
      }

        
else 
        
{
             
if(ViewState["order"].ToString()=="ASC")
            
{
                    ViewState[
"order"]="DESC";
              }

                
else
               
{
                     ViewState[
"order"]="ASC";
                   }

                    
          }

            SqlConnection con
=DB.createCon();
            SqlDataAdapter sda
=new SqlDataAdapter();
            sda.SelectCommand
=new SqlCommand("select employeeID,firstname,title,birthdate from employees",con);
            DataSet ds
=new DataSet();
            sda.Fill(ds,
"emp");
            ds.Tables[
"emp"].DefaultView.Sort=e.SortExpression+" " +ViewState["order"].ToString();
            
this.DataGrid1.DataSource=ds.Tables["emp"].DefaultView;
            
this.DataGrid1.DataBind();

   }

posted on 2006-06-12 11:56    阅读(201)  评论(0)    收藏  举报