救急啊,产品对比功能怎么样实现
我现在在做一个产品对比的功能(类似于淘宝的产品对比)啊 用的是vs2005 语言是C#我已经做了几天了,好累啊,希望大家帮帮我,
前台部分代码:
<asp:Button ID="Button2" runat="server" Text="对比选择商品" OnClick="Button2_Click" /><br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
CellPadding="4" ForeColor="#333333" GridLines="None"
OnPageIndexChanging=" GridView1_PageIndexChanging" Width="100%" AutoGenerateColumns="False">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField FooterText="对比选择" HeaderText="对比选择">
<ItemTemplate>
<input id="Checkbox1" type="checkbox" value='<%#DataBinder.Eval(Container.DataItem,"GoodId")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="图片">
<EditItemTemplate>
</EditItemTemplate>
<ItemTemplate>
<a href='Sellgoodlist.aspx?categoryid=<%#DataBinder.Eval(Container.DataItem,"GoodId")%>'><asp:Image ID="Image1" runat="server" Height="150" ImageUrl='<%# Eval("GoodPicture") %>'
Width="150" /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="标题">
<ItemTemplate>
:<asp:Label ID="Label1" runat="server" Text='<%# Eval("InfoTitle") %>'></asp:Label><br />
用户id<span style="color: #0000ff; text-decoration: underline">:</span><asp:Label ID="Label3"
runat="server" Text='<%# Eval("UserName") %>'></asp:Label><br />
信用: <span title="一钻卖家(101-300个信用积分)">
<img align="middle" src="image/seller01.gif" /><br />
<div>
QQ:<img alt="我在啊!!" height="22" src="image/qqonline.gif" width="16" /><a href="#"
onclick="javascript:AddFavoriteItemEx2('',this,[44,0]);" title="收藏此商品">收藏</a></div>
</span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="新旧">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("NewOld") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="数量">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("GoodQuantity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="价格">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("GoodPrice") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="所在地">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("GoodAddress") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:Button ID="Button6" runat="server" Text="对比选择商品" />
后台:
public partial class Sellgood : System.Web.UI.Page
{
string sqlstr;
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
sqlstr = ConfigurationManager.AppSettings["ConnectionString"];
con = new SqlConnection(sqlstr);
con.Open();
String cmd = "SELECT GoodId, GoodPicture, InfoTitle, UserName, NewOld, GoodQuantity, GoodPrice, GoodAddress FROM SellGood";
SqlDataAdapter myda = new SqlDataAdapter(cmd, con);
DataSet myds = new DataSet();
myda.Fill(myds);
this.GridView1.DataSource = myds;
this.GridView1.DataBind();
this.GridView1.AllowPaging = true;
this.GridView1.PageSize = 10;
con.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
this.GridView1.DataBind();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
string key = this.txtSKWord.Text.Replace(" "," ").ToString();
Response.Redirect("Search.aspx?key="+ Server.UrlEncode(key));
}
protected void Button2_Click(object sender, EventArgs e)
{
sqlstr = ConfigurationManager.AppSettings["ConnectionString"];
con = new SqlConnection(sqlstr);
con.Open();
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
string sql = "select GoodId, GoodPicture, InfoTitle, UserName, NewOld, GoodQuantity, GoodPrice, GoodAddress FROM SellGood where GoodId='" + GridView1.DataKeys[i].Value + "'";
SqlCommand sqlcom = new SqlCommand(sql, con);
con.Open();
sqlcom.ExecuteNonQuery();
con.Close();
}
}
string sqlstr = "select * from GoodSell";
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, con);
DataSet myds = new DataSet();
myda.Fill(myds, "SellGood");
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] { "GoodId" };
GridView1.DataBind();
con.Close();
}
只能显示选中的最后一行数据啊,我想显示选中的所有数据啊
--------------------编程问答-------------------- 我不知道你具体要做什么,
如果是产品对比的话,其时是比较简单就可以实现的
你可以定义一个Session
然后,初始化一个List放到Session中。
当用户每次选择一个产品,即将产品的ID放入List,然后在将List存入Session
在出较产品的时候,将List中产品ID,依次从数据库中读出即可
补充:.NET技术 , ASP.NET