http://www.cnblogs.com/yidishui
获得插入记录标识号
void
Page_Load(
object
sender, System.EventArgs e) 
{
// 数据库连接字符串
string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];
// 创建插入SQL语句及调用@@identity函数返回标识值
string insert_query = "insert into Categories (CategoryName,Description) values ('IT', 'Internet');"
+ "SELECT @@identity AS 'identity';";
// 执行数据库操作
SqlCommand myCommand = new SqlCommand(insert_query, new SqlConnection(ConnStr));
myCommand.Connection.Open();
myLabel.Text = myCommand.ExecuteScalar().ToString();
myCommand.Connection.Close();
}
鼠标移到DataGrid的行更改颜色
private
void
DataGrid1_ItemDataBound(
object
sender, System.Web.UI.WebControls.DataGridItemEventArgs e) 
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
{
//添加自定义属性,当鼠标移过来时设置该行的背景色为"6699ff",并保存原背景色
e.Item.Attributes.Add("onmouseover","StyleColor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
//添加自定义属性,当鼠标移走时还原该行的背景色
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=StyleColor");
}
}
blog site
http://xiexiaokui.cnblogs.com
本文介绍了一种在SQL中使用@@identity函数获取插入记录标识号的方法,并展示了如何通过C#代码实现这一功能。此外,还分享了如何在ASP.NET中使用DataGrid控件,通过添加自定义的JavaScript事件,使鼠标悬停在DataGrid行上时改变其背景颜色,提升用户体验。

被折叠的 条评论
为什么被折叠?



