خرید بک لینک

با سلام و تبریک عید نوروز به تمامی دوستان
من یک دیتا لیست دارم که یک imagebutton و button درون آن هست .میخواهم وقتی کاربر button را کلیک کرد بر اساس رکوردی که imagebutton دارد همان رکورد انتخاب و به سبد خرید اضافه شود.
درواقع چطور productid را تعریف کنم.

کد HTML:

<asp:DataList ID="DataList1" runat="server" DataKeyField="WomenDressID"  DataSourceID="SqlDataSource2" RepeatDirection="Horizontal" RepeatColumns="4"  >              <ItemTemplate>                  <div>                  <li style="list-style:none">                      <asp:ImageButton ID="ImageButton1" runat="server" OnClientClick="retu false" src='<%#Eval("picUrl","images/product/{0}") %>' width="50" height="50" CssClass="imgColor" />                                                          </li>                       </div>                   </ItemTemplate>            </asp:DataList>                </div>             </div>         <asp:SqlDataSource ID="SqlDataSource2" runat="server" CoectionString="<%$ CoectionStrings:ClothingShopCoection %>" SelectCommand="SELECT top 4 * FROM [WomenDress] WHERE ([productName] = @productName)">          <SelectParameters>                <asp:QueryStringParameter Name="productName" QueryStringField="Name" Type="String" />            </SelectParameters>          </asp:SqlDataSource>                 <asp:DataList ID="DataList2" runat="server" DataSourceID="SqlDataSource3" OnItemCommand="DataList2_ItemCommand"  >              <ItemTemplate>                  <div style="width:200px;">                     <div class="mainPrice">                      <asp:Label ID="Label2" runat="server" Text="قیمت اصلی:"></asp:Label>                         </div>                     <div class="valuePrice">                       <asp:Label ID="Label4" runat="server" Text='<%#Eval("price")%>' CssClass="priceDecor"></asp:Label>                         </div>                     </div>                     <div style="width:200px;">                     <div class="mainPrice">                      <asp:Label ID="Label3" runat="server" Text="قیمت با تخفیف:"></asp:Label>                         </div>                     <div class="valuePrice">                       <asp:Label ID="Label5" runat="server" Text='<%#Eval("withDiscount")%>'></asp:Label>                         </div>                      </div>                  <div class="wrapBasket">                      <asp:LinkButton ID="LinkButton1" runat="server" CssClass="btnBasket" CommandName="linkClick"><i class="fa fa-shopping-cart"></i>افزودن به سبد خرید</asp:LinkButton>                  </div>                                                       </ItemTemplate>                </asp:DataList>                             <asp:SqlDataSource ID="SqlDataSource3" runat="server" CoectionString="<%$ CoectionStrings:ClothingShopCoection %>" SelectCommand="SELECT top 1 * FROM [WomenDress] WHERE ([productName] = @productName)">                    <SelectParameters>                     <asp:QueryStringParameter Name="productName" QueryStringField="Name" Type="String" />                </SelectParameters>                </asp:SqlDataSource>
و کد سمت سرور:

protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{
if(e.CommandName == "linkClick")
{
Int64 ProductID =
string script = "Redirect();";
ScriptManager.RegisterStartupScript(this, this.GetType(), "Redirect", script, true);
ShoppingCartAccess.AddItem(ShoppingCartAccess.Shop pingCartId, ProductID);
}
}

public class ShoppingCartAccess
{
public ShoppingCartAccess()
{
//
// TODO: Add constructor logic here
//
}

public static string ShoppingCartId
{
get
{
HttpContext context = HttpContext.Current;
string cartId = "";
object cartIdSession = context.Session["BalloonShop_CartID"];
if (cartIdSession != null)
cartId = cartIdSession.ToString();
if (cartId != "")
retu cartId;
else
{
if (context.Request.Cookies["BalloonShop_CartID"] != null)
{
cartId = context.Request.Cookies["BalloonShop_CartID"].Value;
context.Session["BalloonShop_CartID"] = cartId;
retu cartId;
}
else
{
cartId = Guid.NewGuid().ToString();
HttpCookie cookie = new HttpCookie("BalloonShop_CartID", cartId.ToString());
int howManyDays = BalloonShopConfiguration.cartPersistDays;
DateTime currentDate = DateTime.Now;
TimeSpan timespan = new TimeSpan(howManyDays, 0, 0, 0);
DateTime expirationDate = currentDate.Add(timespan);
cookie.Expires = expirationDate;
context.Response.Cookies.Add(cookie);
context.Session["BalloonShop_CartID"] = cartId;
retu cartId.ToString();

}
}

}
}

public static bool ExecuteSP(string SpName, List<SqlParameter> SPParameters)
{
string CS = ConfigurationManager.CoectionStrings["ClothingShopCoection"].CoectionString;
using (SqlCoection con = new SqlCoection(CS))
{
SqlCommand cmd = new SqlCommand(SpName, con);
cmd.CommandType = CommandType.StoredProcedure;

foreach (SqlParameter parameter in SPParameters)
{
cmd.Parameters.Add(parameter);
}
con.Open();
retu Convert.ToBoolean(cmd.ExecuteScalar());
}
}

public static void AddItem(string cartNum, Int64 proID)
{
List<SqlParameter> paramlist = new List<SqlParameter>()
{
new SqlParameter()
{
ParameterName="@cartID",
Value=cartNum
},

new SqlParameter()
{
ParameterName="@productId",
Value=proID
}
};
ExecuteSP("ShoppingAddItem", paramlist);

}

برچسب: نویسنده: محمد رضا جوادیان تاريخ: يکشنبه 1 فروردين 1395 ساعت: 17:13

صفحه بندی