GridView中的RowCreated事件今天才接触,感觉很不错,能够完成鼠标停留在一行上的圈中效果并能够实现整行作为选择事件, 在实际应用中使用率也比较多
Code
protected void gvwDevelopAlbumStyle_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标进入行时
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C0C0FF';this.style.cursor= 'hand ';");
//鼠标离开行时
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
//任意行都为选择行
//e.Row.Attributes.Add("onClick", "javascript:__doPostBack( '" + this.gvwDevelopAlbumStyle.ID + " ', 'Select$" + e.Row.RowIndex + " ');");
int DevelopAlbumStyleID = Convert.ToInt32(this.gvwDevelopAlbumStyle.DataKeys[e.Row.RowIndex].Value.ToString());
DevelopAlbumStyle das = BLLManage<DevelopAlbumStyle>.GetModel(DevelopAlbumStyleID);
string s = das.ImagePath;
s = s.Replace("\\", "\\\\");
this.TextBox1.Text = s;
e.Row.Attributes.Add("onClick", "javascript:SelectImage('" + s + "','" + das.Name + "');");
}
}
protected void gvwDevelopAlbumStyle_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标进入行时
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C0C0FF';this.style.cursor= 'hand ';");
//鼠标离开行时
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
//任意行都为选择行
//e.Row.Attributes.Add("onClick", "javascript:__doPostBack( '" + this.gvwDevelopAlbumStyle.ID + " ', 'Select$" + e.Row.RowIndex + " ');");
int DevelopAlbumStyleID = Convert.ToInt32(this.gvwDevelopAlbumStyle.DataKeys[e.Row.RowIndex].Value.ToString());
DevelopAlbumStyle das = BLLManage<DevelopAlbumStyle>.GetModel(DevelopAlbumStyleID);
string s = das.ImagePath;
s = s.Replace("\\", "\\\\");
this.TextBox1.Text = s;
e.Row.Attributes.Add("onClick", "javascript:SelectImage('" + s + "','" + das.Name + "');");
}
}