protected void gvBookList_RowDataBound(object sender, GridViewRowEventArgs e) { BooksEx book = e.Row.DataItem as BooksEx; if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#77DD99'"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor"); LinkButton lbDel = e.Row.FindControl("lbDel") as LinkButton; lbDel.Attributes.Add("onclick", $"return confirm(\"你确认要{book.Title}删除吗?\")"); } }
/* * /// <summary> * /// 分页获取数据列表 * /// </summary> * public DataSet GetList(int PageSize,int PageIndex,string strWhere) * { * SqlParameter[] parameters = { * new SqlParameter("@tblName", SqlDbType.VarChar, 255), * new SqlParameter("@fldName", SqlDbType.VarChar, 255), * new SqlParameter("@PageSize", SqlDbType.Int), * new SqlParameter("@PageIndex", SqlDbType.Int), * new SqlParameter("@IsReCount", SqlDbType.Bit), * new SqlParameter("@OrderType", SqlDbType.Bit), * new SqlParameter("@strWhere", SqlDbType.VarChar,1000), * }; * parameters[0].Value = "Books"; * parameters[1].Value = "Id"; * parameters[2].Value = PageSize; * parameters[3].Value = PageIndex; * parameters[4].Value = 0; * parameters[5].Value = 0; * parameters[6].Value = strWhere; * return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds"); * }*/ #endregion BasicMethod #region ExtensionMethod public List <BooksEx> GetAllBooks() { List <BooksEx> booklist = new List <BooksEx>(); StringBuilder sb = new StringBuilder(); sb.AppendLine("select b.id,b.Title,b.Author,p.Id as PublisherId,p.Name as PublisherName,"); sb.AppendLine("b.PublishDate,b.ISBN,b.UnitPrice,b.ContentDescription,b.Toc,"); sb.AppendLine("b.Clicks,c.Id as CategoryId,c.Name as CategoryName,c.Pid,c.SortNum"); sb.AppendLine("from Books as b inner join Publishers as p on b.PublisherId=p.Id"); sb.AppendLine("inner join Categories as c on b.CategoryId=c.Id;"); SqlDataReader reader = DbHelperSQL.ExecuteReader(sb.ToString()); while (reader.Read()) { BooksEx book = new BooksEx(); book.Id = int.Parse(reader["Id"].ToString()); book.Title = reader["Title"].ToString(); book.Author = reader["Author"].ToString(); book.PublisherId = int.Parse(reader["PublisherId"].ToString()); Publishers p = new Publishers(); p.Id = int.Parse(reader["PublisherId"].ToString()); p.Name = reader["PublisherName"].ToString(); book.Publishers = p; book.PublishDate = DateTime.Parse(reader["PublishDate"].ToString()); book.ISBN = reader["ISBN"].ToString(); book.UnitPrice = decimal.Parse(reader["UnitPrice"].ToString()); book.ContentDescription = reader["ContentDescription"].ToString(); book.TOC = reader["TOC"].ToString(); book.CategoryId = int.Parse(reader["CategoryId"].ToString()); Categories c = new Categories(); c.Id = int.Parse(reader["CategoryId"].ToString()); c.Name = reader["CategoryName"].ToString(); c.PId = int.Parse(reader["PId"].ToString()); c.SortNum = string.IsNullOrEmpty(reader["SortNum"].ToString()) ? 0 : int.Parse(reader["SortNum"].ToString()); book.Categories = c; book.Clicks = int.Parse(reader["Clicks"].ToString()); booklist.Add(book); } return(booklist); }