ASP.NET常用代码

http://tech.ddvip.com   2007年09月02日    社区交流

内容摘要:ASP.NET常用代码

  3.2样式交替:

ListItemType itemType = e.Item.ItemType;
  
if (itemType == ListItemType.Item )
  
{
  
e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#FFFFFF';";
  
e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#d9ece1';cursor='hand';" ;
  
}
  
else if( itemType == ListItemType.AlternatingItem)
  
{
  
e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#a0d7c4';";
  
e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#d9ece1';cursor='hand';" ;
  
}

  3.3添加一个编号列:

DataTable dt= c.ExecuteRtnTableForAccess(sqltxt); //执行sql返回的DataTable
  
DataColumn dc=dt.Columns.Add("number",System.Type.GetType("System.String"));
  
for(int i=0;i<dt.Rows.Count;i++)
  
{
  
dt.Rows[i]["number"]=(i+1).ToString();
  
}
  
DataGrid1.DataSource=dt;
  
DataGrid1.DataBind();

  3.4 DataGrid1中添加一个CheckBox,页面中添加一个全选框

private void CheckBox2_CheckedChanged(object sender, System.EventArgs e)
  
{
  
foreach(DataGridItem thisitem in DataGrid1.Items)
  
{
  
((CheckBox)thisitem.Cells[0].Controls[1]).Checked=CheckBox2.Checked;
  
}
  
}

作者:周建东    责编:豆豆技术应用

正在加载评论...