源代码:13033480群共享
一、在数据库表Item中添加字段Descn、SupplyTime、SupplyDate、SupplyArea。因为除Descn,其它几个字段内容都差不多,所以,设置一下默认值,以后添加,更新数据库内容时,会更方便。二、在数据集Model类库中添加类ItemDetails.cs。
using System;
namespace WestGarden.Model
{
public class ItemDetails
{
private int itemid;
private string categoryid;
private string name;
private decimal price;
private string image;
private string categoryname;
private string descn;
private string supplytime;
private string supplydate;
private string supplyarea;
public ItemDetails() { }
public ItemDetails(int itemid, string categoryid, string name, decimal price, string image, string categoryname,
string descn, string supplytime,string supplydate,string supplyarea)
{
this.itemid = itemid;
this.categoryid = categoryid;
this.name = name;
this.price = price;
this.image = image;
this.categoryname = categoryname;
this.descn = descn;
this.supplytime = supplytime;
this.supplydate = supplydate;
this.supplyarea = supplyarea;
}
public int ItemId
{
get { return itemid; }
set { itemid = value; }
}
public string CategoryId
{
get { return categoryid; }
set { categoryid = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public decimal Price
{
get { return price; }
set { price = value; }
}
public string Image
{
get { return image; }
set { image = value; }
}
public string CategoryName
{
get { return categoryname; }
set { categoryname = value; }
}
public string Descn
{
get { return descn; }
set { descn = value; }
}
public string SupplyTime
{
get { return supplytime; }
set { supplytime = value; }
}
public string SupplyDate
{
get { return supplydate; }
set { supplydate = value; }
}
public string SupplyArea
{
get { return supplyarea; }
set { supplyarea = value; }
}
}
}
三、在数据访问层DAL的Item.cs类中添加函数GetItemDetailsByItemId()
public IList<ItemDetails> GetItemDetailsByItemId(int ItemId)
{
IList<ItemDetails> itemDetailsByItemId = new List<ItemDetails>();
SqlParameter parm = new SqlParameter(PARM_ITEM_ID, SqlDbType.Int);
parm.Value = ItemId;
using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_ITEMDETAILS_BY_CATEGORY, parm))
{
while (rdr.Read())
{
ItemDetails item = new ItemDetails(rdr.GetInt32(0), rdr.GetString(1), rdr.GetString(2), rdr.GetDecimal(3), rdr.GetString(4), rdr.GetString(5),rdr.GetString(6),rdr.GetString(7),rdr.GetString(8),rdr.GetString(9));
itemDetailsByItemId.Add(item);
}
}
return itemDetailsByItemId;
}
四、Controls中添加用户控件ItemDetailsControl.ascx
1、前台代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ItemDetailsControl.ascx.cs" Inherits="WestGarden.Web.ItemDetailsControl" %>
<%@ Register TagPrefix="WestGardenControl" Namespace="WestGarden.Web" %>
<div>
<asp:FormView ID="fvwItemDetails" runat="server">
<ItemTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td height="18" width="18">
</td>
<td height="18" width="96">
</td>
<td height="18" width="18">
</td>
<td height="18" width="96">
</td>
<td height="18" width="180">
</td>
</tr>
<tr>
<td width="18">
</td>
<td rowspan="7" width="96">
<asp:Image Width="144" Height="144" ID="imgItem" ImageUrl='<%# Eval("Image") %>'
AlternateText='<%# Eval("Name") %>' runat="server" /></td>
<td width="18">
</td>
<td width="96">
商品类别:</td>
<td width="180">
<%# Eval("CategoryName") %>
</td>
</tr>
<tr>
<td width="18">
</td>
<td width="18">
</td>
<td width="96">
商品名称:</td>
<td width="180">
<%# Eval("Name") %>
</td>
</tr>
<tr>
<td width="18">
</td>
<td width="18">
</td>
<td width="96">
商品价格:</td>
<td width="180">
<%# Eval("Price") %>
</td>
</tr>
<tr>
<td width="18">
</td>
<td width="18">
</td>
<td width="96">
商品描述:</td>
<td width="180">
<%# Eval("Descn") %>
</td>
</tr>
<tr>
<td width="18">
</td>
<td width="18">
</td>
<td width="96">
供应时间:</td>
<td width="180">
<%# Eval("SupplyTime") %>
</td>
</tr>
<tr>
<td width="18">
</td>
<td width="18">
</td>
<td width="96">
供应日期:</td>
<td width="180">
<%# Eval("SupplyDate") %>
</td>
</tr>
<tr>
<td width="18">
</td>
<td width="18">
</td>
<td width="96">
供应地区:</td>
<td width="180">
<%# Eval("SupplyArea") %>
</td>
</tr>
<tr>
<td height="18" width="18">
</td>
<td height="18" width="96">
</td>
<td height="18" width="18">
</td>
<td height="18" width="96">
</td>
<td height="18" width="180">
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
</div>
<div><a href='Items.aspx?categoryId=<%=Request.QueryString["categoryId"] %>'><返回</a></div>
2、后台代码
using System;
using System.Web;
using System.Web.UI.WebControls;
using WestGarden.DAL;
namespace WestGarden.Web
{
public partial class ItemDetailsControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
int itemKey = int.Parse(Request.QueryString["itemId"]);
Item item = new Item();
fvwItemDetails.DataSource = item.GetItemDetailsByItemId(itemKey);
fvwItemDetails.DataBind();
}
}
}
五、Web中添加窗体ItemDetails.aspx并选择母版页MasterPage.master,拖入用户控件ItemDetailsControl.ascx,并在Page_Load()函数中添加代码:
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = WebUtility.GetCategoryName(Request.QueryString["categoryId"]);
}
分享到:
相关推荐
formview分页上一页下一页总页数当前页数首页末页
ASP.NET2.0中编程实现GridView与FormView的主-详细视图
详细的介绍了fromview的使用方法,加上本人实例
FormView控件的运用
formview.css
这是用vs建的一个例子,关于GridView控件和FormView控件的。
GridView_+_FormView_+_SqlDataSource
网站上自己下载的代码 运行了一遍 有一些收获 有兴趣的可以自己下载看看 免费下载的哦
代码演示了怎么在CFormView中增加CEditView
一个基于FormView的扩展类,允许控件以不同形式随窗体变化
这个是Windows FormView的程序,实现基本的FormView功能。
控制了窗口的大小当拖动窗口缩小的添加的空间大小时,窗口不会再缩小了,实现了formview dialog对话框的布局,还有就是点击菜单项切换界面,
论坛上有很多人使用对话框的scrollBar控制对话框中一部分的卷动,实现过程复杂而且逻辑混乱。这个例子里,直接在对话框中创建一个CFormView子窗口,子窗口自己管理卷动,各负其责,条理清晰
listbox,datasousce 应用以及
基于FormView的多语言界面程序,通过定义多种语言的lng文件,即可轻松实现语言的切换
FormView 视图 无法响应Ctrl+C等键盘消息解决办法 仅4行代码 无需对单个Editbox控件修改,非常好用 仅需2资源分
GridView与FormView结合使用,实现增删改查,第一种方法,用数据源绑定完成!第二种方法,全部用代码完成!
自制的基于MFC、OpenGL平台的平面二维坐标图程序,支持大数据量绘图。程序在VS2010下编译通过。
开发环境 VS2010+SQLServer2005 W7系统 使用技术:ASP.NET DIV+CSS 使用控件:母板页、主题、站点导航、树形菜单、GridView、FormView、Repeater、DataList 高级功能:真分页、批量删除、光棒、购物车(在线购物和...