There is an add to cart link on one gridview and just a command button on the other
Here is the page
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="wsiAdvancedSearch.ascx.cs" Inherits="ConLib_wsiAdvancedSearch" %>
<%--
<conlib>
<summary>Displays an advanced search page, to search products in the catalog.</summary>
</conlib>
--%>
<%@ Register Src="~/ConLib/Utility/ProductPrice.ascx" TagName="ProductPrice" TagPrefix="uc" %>
<%@ Register Src="~/ConLib/AddToCartLink.ascx" TagName="AddToCartLink" TagPrefix="uc" %>
<%@ Register Src="~/ConLib/wsiAdd2CartLink.ascx" TagName="ExtAddToCartLink" TagPrefix="uc" %>
<div class="pageHeader">
<h1 class="heading">Advanced Search</h1>
</div>
<asp:Literal ID="LT" runat="server" Text=""></asp:Literal>
<table class="inputForm">
<tr>
<th class="rowHeader" valign="top">
<asp:Label ID="KeywordsLabel" runat="server" Text="Search Keywords:"></asp:Label>
</th>
<td>
<asp:TextBox ID="Keywords" runat="server"></asp:TextBox><br />
<asp:Label ID="WildCardMessage" runat="server" Text="Wild Cards * and ? may be used."></asp:Label>
</td>
</tr>
<tr>
<th class="rowHeader">
<asp:Label ID="SearchInLabel" runat="server" Text="Search In:"></asp:Label>
</th>
<td>
<asp:CheckBox ID="SearchName" runat="server" Text="Name" Checked="true" />
<asp:CheckBox ID="SearchDescription" runat="server" Text="Description" />
<asp:CheckBox ID="SearchSKU" runat="server" Text="SKU" />
</td>
</tr>
<tr>
<th class="rowHeader">
<asp:Label ID="CategoryLabel" runat="server" Text="Select Category:"></asp:Label>
</th>
<td>
<asp:DropDownList ID="CategoryList" runat="server" AppendDataBoundItems="True"
DataTextField="Name" DataValueField="CategoryId">
<asp:ListItem Text="- Any Category -" Value="0"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<th class="rowHeader">
<asp:Label ID="ManufacturerLabel" runat="server" Text="Select Manufacturer:"></asp:Label>
</th>
<td>
<asp:DropDownList ID="ManufacturerList" runat="server" AppendDataBoundItems="True"
DataSourceID="ManufacturerDs" DataTextField="Name" DataValueField="ManufacturerId">
<asp:ListItem Text="- Any Manufacturer -" Value="0"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<th class="rowHeader">
<asp:Label ID="PriceRangeLabel" runat="server" Text="Price Range:"></asp:Label>
</th>
<td>
<asp:Label ID="Label4" runat="server" Text="Low:"></asp:Label>
<asp:TextBox ID="LowPrice" runat="server" Columns="4" MaxLength="4"></asp:TextBox>
<asp:RangeValidator ID="LowPriceValidator1" runat="server" Type="Currency" MinimumValue="0" MaximumValue="99999999" ControlToValidate="LowPrice" ErrorMessage="Low price must be a valid value." Text="*"></asp:RangeValidator>
<asp:Label ID="Label3" runat="server" Text="High:"></asp:Label>
<asp:TextBox ID="HighPrice" runat="server" Columns="4" MaxLength="4"></asp:TextBox>
<asp:RangeValidator ID="HighPriceValidator1" runat="server" Type="Currency" MinimumValue="0" MaximumValue="99999999" ControlToValidate="HighPrice" ErrorMessage="High price must be a valid value.<br/>" Text="*"></asp:RangeValidator>
<asp:CompareValidator ID="LowHighPriceValidator1" runat="server" Type="Currency" Operator="GreaterThanEqual" ControlToValidate="HighPrice" ControlToCompare="LowPrice" ErrorMessage="High price should be greater then low price." Text="*" ></asp:CompareValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:ValidationSummary ID="ValidationSummary2" runat="server" /><br />
</td>
</tr>
<tr>
<td colspan="2" align="right">
<asp:Button ID="SearchButton" runat="server" OnClick="SearchButton_Click" Text="Search" /><br />
</td>
</tr>
</table>
<div class="section">
<div id="SearchResultHeading" runat="server" class="header" visible="false">
<h2>Search Results</h2>
</div>
<asp:GridView ID="ProductsGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductId"
Width="100%" SkinID="PagedList" AllowPaging="true" PageSize="25" AllowSorting="true"
DataSourceID="ProductDs" Visible="false" >
<Columns>
<asp:BoundField DataField="Sku" HeaderText="SKU" SortExpression="Sku">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<ItemTemplate>
<asp:HyperLink ID="Name" runat="server" Text='<%#Eval("Name")%>' NavigateUrl='<%#Eval("NavigateUrl")%>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Manufacturer" SortExpression="Manufacturer">
<ItemTemplate>
<asp:Label ID="Manufacturer" runat="server" Text='<%#GetManufacturerLink((int)Eval("ManufacturerId"))%>'
></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Categories">
<ItemTemplate>
<asp:PlaceHolder ID="Categories" runat="server"></asp:PlaceHolder>
<asp:Literal ID="CategoriesList" runat="server" Text='<%#GetCatsList(Container.DataItem)%>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Retail Price" SortExpression="MSRP">
<HeaderStyle HorizontalAlign="Center" Width="80px" />
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="MSRP" runat="server" Text='<%#GetMSRP(Container.DataItem)%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Our Price" SortExpression="Price">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<uc:ProductPrice ID="Price" runat="server" Product='<%#Container.DataItem%>' PriceLabel=""></uc:ProductPrice>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<uc:AddToCartLink ID="Add2Cart" runat="server" ProductId='<%#Eval("ProductId")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Localize ID="EmptyMessage" runat="server" Text="- no matching products -"></asp:Localize>
</EmptyDataTemplate>
</asp:GridView>
</div>
<asp:ObjectDataSource ID="ProductDs" runat="server" DataObjectTypeName="CommerceBuilder.Products.Product"
OldValuesParameterFormatString="original_{0}" SelectMethod="AdvancedSearch" SortParameterName="sortExpression"
TypeName="CommerceBuilder.Products.ProductDataSource">
<SelectParameters>
<asp:ControlParameter Name="keyword" Type="String" ControlID="Keywords" PropertyName="Text" />
<asp:ControlParameter Name="categoryId" Type="Int32" ControlID="CategoryList" PropertyName="SelectedValue" />
<asp:ControlParameter Name="manufacturerId" Type="Int32" ControlID="ManufacturerList" PropertyName="SelectedValue" />
<asp:ControlParameter Name="searchName" Type="boolean" ControlID="SearchName" PropertyName="Checked" />
<asp:ControlParameter Name="searchDescription" Type="boolean" ControlID="SearchDescription" PropertyName="Checked" />
<asp:ControlParameter Name="searchSKU" Type="boolean" ControlID="SearchSKU" PropertyName="Checked" />
<asp:ControlParameter Name="lowPrice" Type="decimal" ControlID="LowPrice" PropertyName="Text" />
<asp:ControlParameter Name="highPrice" Type="decimal" ControlID="HighPrice" PropertyName="Text" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ManufacturerDs" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="LoadForStore" TypeName="CommerceBuilder.Products.ManufacturerDataSource">
<SelectParameters>
<asp:Parameter Name="sortExpression" DefaultValue="Name" />
</SelectParameters>
</asp:ObjectDataSource>
<br />
<br />
<div id="DivAdd" runat="server" class="header" visible="false">
<h2>Additional Parts in Warehouse</h2>
</div>
<br />
<br />
<asp:GridView ID="ExternalGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="partsno"
Width="100%" SkinID="PagedList" AllowPaging="true" PageSize="25" AllowSorting="true"
onrowcommand="ext_RowCommand">
<Columns>
<asp:BoundField DataField="partsno" HeaderText="SKU" SortExpression="Sku">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="mfg" HeaderText="Manufacturer" SortExpression="Sku">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="description" HeaderText="Name" SortExpression="Sku">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server"
CommandName="AddCart" SkinID="BuyNowButton" CausesValidation="false"
CommandArgument="<%# Container.DataItemIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Localize ID="EmptyMessage" runat="server" Text="- no matching products -"></asp:Localize>
</EmptyDataTemplate>
</asp:GridView>
<asp:HiddenField ID="VS" runat="server" />
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Xml;
using CommerceBuilder.Common;
using CommerceBuilder.Catalog;
using CommerceBuilder.Products;
using CommerceBuilder.Orders;
using CommerceBuilder.Utility;
public partial class ConLib_wsiAdvancedSearch : System.Web.UI.UserControl
{
private int _ProductId;
public int ProductId
{
get { return _ProductId; }
set { _ProductId = value; }
}
protected void SearchButton_Click(object sender, EventArgs e)
{
BindProductsGrid();
BindExternal();
}
private void BindProductsGrid()
{
SearchResultHeading.Visible = true;
ProductsGrid.Visible = true;
ProductsGrid.PageIndex = 0;
ProductsGrid.DataBind();
}
protected void BindExternal()
{
string myurl;
string srchStr;
string catStr;
string manStr;
string keyStr;
srchStr = "";
DivAdd.Visible = false;
catStr = CategoryList.SelectedItem.Text;
manStr = ManufacturerList.SelectedItem.Text;
keyStr = Keywords.Text;
if (catStr.IndexOf("Any") == -1)
srchStr += catStr;
if (manStr.IndexOf("Any") == -1)
{
srchStr += " " + manStr;
}
if (keyStr.Length > 0)
srchStr += " " + keyStr;
//Response.Write("XXXXXXXX " + srchStr + "ZZZZ " + manStr);
DataSet ds = new DataSet();
try
{
myurl = "
http://2.0.ittrader.com/?keycode=Humm7165&keyword=" + srchStr;
ds.ReadXml(myurl);
ExternalGrid.DataSource = ds.Tables[0];
ExternalGrid.DataBind();
DivAdd.Visible = true;
}
catch (IndexOutOfRangeException e)
{
return;
}
}
protected void ext_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "AddCart")
{
AddExternal(Convert.ToInt32(e.CommandArgument));
}
}
private void AddExternal(Int32 index)
{
Int32 pID;
pID = AddProduct(index);
BasketItem basketItem = BasketItemDataSource.CreateForProduct(pID, 1);
//ADD ITEM TO BASKET
Basket basket = Token.Instance.User.Basket;
basket.Items.Add(basketItem);
basket.Save();
//Response.Redirect("Basket.aspx");
}
private Int32 AddProduct(Int32 index)
{
Product _Product = new Product();
GridViewRow selectedRow = ExternalGrid.Rows[index];
string model = selectedRow.Cells[0].Text;
string desc = selectedRow.Cells[2].Text;
_Product.Name = desc;
_Product.Sku = "EXT";
_Product.Price = 0;
_Product.MSRP = 0;
_Product.ManufacturerId = 0;
_Product.ModelNumber = model;
_Product.Summary = model + " " + desc;
_Product.Description = model + " " + desc;
_Product.Save();
return _Product.ProductId;
}
protected void InitializeCategoryTree()
{
CategoryLevelNodeCollection categories = CategoryParentDataSource.GetCategoryLevels(0, true);
foreach (CategoryLevelNode node in categories)
{
string prefix = string.Empty;
for (int i = 0; i <= node.CategoryLevel; i++) prefix += " . . ";
CategoryList.Items.Add(new ListItem(prefix + node.Name, node.CategoryId.ToString()));
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
InitializeCategoryTree();
}
PageHelper.SetDefaultButton(Keywords, SearchButton.ClientID);
PageHelper.SetDefaultButton(LowPrice, SearchButton.ClientID);
PageHelper.SetDefaultButton(HighPrice, SearchButton.ClientID);
}
protected String GetCatsList(object product)
{
Product p = (Product)product;
StringBuilder output = new StringBuilder();
foreach (int categoryId in p.Categories)
{
Category category = CategoryDataSource.Load(categoryId);
if (category != null)
{
output.Append("<a href=\"" + Page.ResolveUrl(category.NavigateUrl) + "\" >" + category.Name + "</a>, ");
}
}
// REMOVE LAST COMMA
String retValue = output.ToString();
if (!String.IsNullOrEmpty(retValue))
{
return retValue.Substring(0, retValue.Length - 2);
}
else
{
return retValue;
}
}
protected string GetManufacturerLink(int manufacturerId)
{
Manufacturer manufacturer = ManufacturerDataSource.Load(manufacturerId);
if (manufacturer != null)
{
return manufacturer.Name;
}
return String.Empty;
}
protected string GetMSRP(object obj)
{
Product prod = obj as Product;
if (prod != null && !prod.UseVariablePrice && prod.MSRP > 0)
{
//return String.Format("{0:lc}", prod.MSRP);
return prod.MSRP.ToString("ulc");
}
else
{
return string.Empty;
}
}
}
Do I need to set VS to something?