当鼠标经过某一行时,使其突出显示,增加视觉效果,代码如下:
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#9CCBF7'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
鼠标经过的行颜色为#9CCBF7,鼠标移开是又变回原来颜色,这里用c先保存原来的颠值!
以上代码放在ItemDataBind事件中即可
datagrid删除确认
{
LinkButton mydel=(LinkButton)e.Item.FindControl ("btndel");
if(mydel!=null)
{
mydel.Attributes .Add ("onclick","return confirm('确认删除吗?');");
}
}
datagrid排序
private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
DataSet ds=new DataSet();
ds=DB.getdataset ("select * from mytab");
DataView dv=ds.Tables [0].DefaultView ;
dv.Sort=e.SortExpression ;
DataGrid1 .DataSource =dv;
DataGrid1 .DataBind ();
}
实现双向排序...
if(ViewState["order"]==null)
{
ViewState["order"]="asc";
}
else
{
if(ViewState["order"].ToString ()=="asc")
{
ViewState["order"]="desc";
}
else
{
ViewState["order"]="asc";
}
}
SqlConnection mycon=DB.creatcon ();
SqlDataAdapter da=new SqlDataAdapter ("select * from student order by studentid desc ",mycon);
DataSet ds=new DataSet() ;
da.Fill (ds,"tabnew");
DataView dv=ds.Tables [0].DefaultView ;
dv.Sort =e.SortExpression+" "+ViewState["order"].ToString();
DataGrid1.DataSource =dv;
DataGrid1 .DataBind ();