hi.i bring link button inside datalist.but dont know how get productid from any imagebutton when clicked on it. i want use commandargument proprty but have two different datasource so how get commandargument in datalist1 that is clicked on imagebutton and use in datalist2 for productID.with these explanations how define productID? more info: when i click on imagebutton is executed a dynamic slideshow and i want from a few color for dress only a color is selected.Thanks
<asp:datalist id="DataList1" runat="server" datakeyfield="WomenDressID" datasourceid="SqlDataSource2" repeatdirection="Horizontal" repeatcolumns="4" xmlns:asp="#unknown">
<itemtemplate>
<div>
<li style="list-style:none">
<asp:imagebutton id="ImageButton1" runat="server" onclientclick="return false" commandname="click" commandargument="<%# Eval("WomenDressID") %>" src="<%#Eval("picUrl","images/product/{0}") %>" width="50" height="50" cssclass="imgColor" />
</li>
</div>
</itemtemplate>
</asp:datalist>
<asp:sqldatasource id="SqlDataSource2" runat="server" connectionstring="<%$ ConnectionStrings:ClothingShopConnection %>" selectcommand="SELECT top 4 * FROM [WomenDress] WHERE ([productName] = @productName)" xmlns:asp="#unknown">
<SelectParameters>
<asp:querystringparameter name="productName" querystringfield="Name" type="String" />
</SelectParameters>
</asp:sqldatasource>
<asp:datalist id="DataList2" runat="server" datasourceid="SqlDataSource3" onitemcommand="DataList2_ItemCommand" xmlns:asp="#unknown">
<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">افزودن به سبد خرید</asp:linkbutton>
</div>
</itemtemplate>
</asp:datalist>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ClothingShopConnection %>" SelectCommand="SELECT top 1 * FROM [WomenDress] WHERE ([productName] = @productName)">
<SelectParameters>
<asp:QueryStringParameter Name="productName" QueryStringField="Name" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
and codebehind
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.ShoppingCartId, ProductID);
}
}
public class ShoppingCartAccess
{
public ShoppingCartAccess()
{
}
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 != "")
return cartId;
else
{
if (context.Request.Cookies["BalloonShop_CartID"] != null)
{
cartId = context.Request.Cookies["BalloonShop_CartID"].Value;
context.Session["BalloonShop_CartID"] = cartId;
return 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;
return cartId.ToString();
}
}
}
}
public static bool ExecuteSP(string SpName, List<sqlparameter> SPParameters)
{
string CS = ConfigurationManager.ConnectionStrings["ClothingShopConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand(SpName, con);
cmd.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter parameter in SPParameters)
{
cmd.Parameters.Add(parameter);
}
con.Open();
return 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);
}
}
}
</sqlparameter>
What I have tried:
ASP.NET, c#,ASP.NET, c#,,ASP.NET, C#3.5, ASP.NET, c#