-
31-07-2011, 08:56 AM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
ẩn giỏ hàng khi chưa đăng nhập vào trang web như thế nào?
Em đang làm project về bán hàng, em muốn khi người dùng chưa đăng nhập vào trang web thì giỏ hàng sẽ ẩn đi, khi nào đăng nhập vào thì giỏ hàng sẽ hiện ra để người dùng có thể sử dụng. Nhờ các anh giúp em với. Em xin cãm ơn trước
View more random threads:
- Không chuyển được String sang Datetime
- Lấy ID trong DataList với lập trình ASP.NET
- thắc mắc về đưa cơ sở dữ liệu Access lên hiên thị datagridview
- Hàm nào kiểm tra trang ASP.NET đã Load xong hay chưa?
- Kiểm tra có kết nối internet hay ko như thế nào?
- Cách hiển thị dữ liệu của label lên dropdownlist đã có sẵn dữ liệu load từ database?
- Cách lọc sản phẩm theo tên gần đúng trong LinQ
- Format ,hiển thị giá của sản phẩm trong ASP.NET?
- Hiện trạng thái Online/Offline của nhân viên hỗ trợ
- Lỗi hiện thị Share trang facebook?
-
31-07-2011, 09:07 AM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi lytieuchieu
ASP thì mình không biết.Chỉ biết PHP . đây là ví dụ đơn giản bên php:
Mã:<?php session_start(); if(isset($_SESSION['user'])&&!empty($_SESSION['user'])) { // show đoạn mã php,html... liên quan đến giở hàng lên. }else // không hiện giỏ hàng ,vì chưa đang nhập?>
-
31-07-2011, 09:09 AM #3Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi tauit_dnmdMã:<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> // show đoạn mã php,html... liên quan đến giở hàng lên. }else // không hiện giỏ hàng ,vì chưa đang nhập?>
</div>
</div>
</div>Em cảm ơn để em làm thử
-
31-07-2011, 02:17 PM #4Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
trong asp thì cái giỏ hàng của bạn thiết kế VD: bạn sử dụng datalist để hiển thị dữ liệu lên giỏ hàng, giờ bạn bỏ datalist vào cái penal rồi kiểm tra điều kiện của người dùng, mà cho ẩn cái penal.enable=true or false
-
01-08-2011, 09:06 AM #5Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
cho cái giỏ hàng vào cái panel (ví dụ id="panel1") hoặc cái gì dạng container.
kiểm tra user đã đăng nhập chưa, cái này chắc chắn là bạn làm được (ko làm được thì khỏi làm cái bước sau)
if (<dk kiểm tra đăng nhập>==true)
panel1.visible = false;// ẩn đi
else
panel1.visible = true;// Hiện ra
Enjoy!
-
01-08-2011, 11:11 AM #6Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi kunnau127
Đây là giao diện:
<%@ Page Title="" Language="C#" MasterPageFile="~/MyMasterPage.Master" AutoEventWireup="true" CodeBehind="Detail.aspx.cs" Inherits="webHuong.Detail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:OnlineShoppingConnectionString %>"
SelectCommand="SELECT * FROM [ProductDetail] WHERE ([PrID] = @PrID)">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="101" Name="PrID"
QueryStringField="ProID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp[IMG]images/smilies/biggrin.png[/IMG]ataList ID="DataList1" runat="server" DataKeyField="PrID"
DataSourceID="SqlDataSource1" onitemcommand="DataList1_ItemCommand">
<ItemTemplate>
<table style="width:100%;">
<tr>
<td>
<asp:Image ID="Image1" runat="server" Height="100px"
ImageUrl='<%# "Images/" + Eval("Image") %>' Width="100px" />
</td>
<td>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
Description:</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("PrDescription") %>'></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Panel ID="Panel1" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument='<%# Eval("PrID") %>'>Add to cart</asp:LinkButton>
</asp:Panel>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
</table>
</ItemTemplate>
</asp[IMG]images/smilies/biggrin.png[/IMG]ataList>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace webHuong
{
public partial class Detail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
string PrId = e.CommandArgument.ToString();
int qty = int.Parse(((TextBox)e.Item.FindControl("TextBox1") ).Text);
string connstring = ConfigurationManager.ConnectionStrings["OnlineShoppingConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connstring);
SqlCommand comm = new SqlCommand("select * from dbo.ProductDetail where PrID = @PrID",conn);
comm.Parameters.AddWithValue("@PrID", PrId);
conn.Open();
SqlDataReader sdr = comm.ExecuteReader();
if (sdr.HasRows)
{
sdr.Read();
string PrName = sdr["PrName"].ToString();
string PrDescription = sdr["PrDescription"].ToString();
string Image = sdr["Image"].ToString();
double Rate = double.Parse(sdr["Rate"].ToString());
//check session
if (Session["ShoppingCart"] == null)
{
DataTable dt = new DataTable();
dt.Columns.Add("PrID", typeof(int));
dt.Columns.Add("PrName", typeof(string));
dt.Columns.Add("PrDescription", typeof(string));
dt.Columns.Add("Image", typeof(string));
dt.Columns.Add("Rate", typeof(double));
dt.Columns.Add("Quantity", typeof(int));
dt.Constraints.Add("pk_PrId", dt.Columns[0], true);
Session["ShoppingCart"] = dt;
}
DataRow dr = ((DataTable)Session["ShoppingCart"]).NewRow();
dr["PrID"] = PrId;
dr["PrName"] = PrName;
dr["PrDescription"] = PrDescription;
dr["Image"] = Image;
dr["Rate"] = Rate;
dr["Quantity"] = qty;
bool hasThisProduct = false;
for (int rowId = 0; rowId < ((DataTable)Session["ShoppingCart"]).Rows.Count; rowId++)
{
if (((DataTable)Session["ShoppingCart"]).Rows[rowId]["PrId"].ToString() == dr["PrId"].ToString())
{
int rowQty = int.Parse(((DataTable)Session["ShoppingCart"]).Rows[rowId]["Quantity"].ToString());
((DataTable)Session["ShoppingCart"]).Rows[rowId]["Quantity"] = rowQty + int.Parse(dr["Quantity"].ToString());
hasThisProduct = true;
break;
}
}
if(!hasThisProduct)
((DataTable)Session["ShoppingCart"]).Rows.Add(dr);
Response.Redirect("ShoppingCart.aspx");
}
}
}
}
-
01-08-2011, 04:44 PM #7Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Mình nghĩ bạn không cần phải hide cái giỏ hàng đi. Cách mình thường làm kiểm tra nếu chưa login thì set cho nó 0 item 0 price. Còn nếu đã đăng nhập thì visible thông tin giỏ hàng
-
01-08-2011, 07:25 PM #8Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Anh giải thích cụ thể hơn 1 chút được không ạh
-
02-08-2011, 06:52 PM #9Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Nếu như trang web của bạn sử dụng ASP.NET Membership thì bạn sử dụng LoginView để hiển thị các nội dung khác nhau tùy theo người dùng đã đăng nhập hay chưa.
-
03-08-2011, 10:23 AM #10Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi kunnau127
Pallet nhựa Lâm Đồng giải pháp hoàn hảo cho nhà kho Pallet nhựa Lâm Đồng là một giải pháp đa năng và hiệu quả trong việc vận chuyển và lưu trữ hàng hóa. Trong đó, pallet nhựa Lâm Đồng không chỉ đáp...
Pallet nhựa Lâm Đồng giải pháp...