using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class OnlineOrder : System.Web.UI.Page
{
DataTable Basket_DataTable = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["basket"] != null)
///read Basket_DataTable from session if exist
Basket_DataTable = (DataTable)Session["basket"];
else
{
//create an empty DataTable and Add some columns to it
Basket_DataTable = new DataTable();
Basket_DataTable.Columns.Add("Itemsid");
Basket_DataTable.Columns.Add("Items");
Basket_DataTable.Columns.Add("Price");
Basket_DataTable.Columns.Add("count");
Basket_DataTable.Columns.Add("total");
}
/////////////////////////
//if (Request["DelID"] != null)
//{
// for (int i = 0; i < Basket_DataTable.Rows.Count; i++)
// if (Basket_DataTable.Rows[i][0].ToString() == Request["DelID"].ToString())
// Basket_DataTable.Rows.Remove(Basket_DataTable.Rows[i]);
//}
if (Request["ID"] != null)
{
//search item in DataTable
bool Found = false;
for (int i = 0; i < Basket_DataTable.Rows.Count; i++)
if (Basket_DataTable.Rows[i][0].ToString() == Request["ID"].ToString())
Found = true;
//add to basket
if (Found == false)
{
DataAcess data = new DataAcess();
string sql = "SELECT * FROM Items where Itemsid=" + Request["ID"];
DataTable ret = data.exe_select(sql);
if (ret != null && ret.Rows.Count == 1)
{
Basket_DataTable.Rows.Add(new object[] { Request["ID"],ret.Rows[0]["Items"].ToString()
,ret.Rows[0]["Price"].ToString(),"1"});
// Basket_DataTable.Columns["a4"]. = false;
}
}
}
/////////////////////////
GridView4.DataBind();
Session["basket"] = Basket_DataTable;
}
}
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
Response.Redirect("~/OnlineOrder.aspx?group=" + e.CommandArgument);
GridView4.DataBind();
}
}
<%@ Page Title="" Language="C#" MasterPageFile="~/HBHB.master" AutoEventWireup="true" CodeFile="OnlineOrder.aspx.cs" Inherits="OnlineOrder" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.col
{
padding-right:10px;
padding-left:50px;
}
.itemb1 {
font-size:16px;
font-family:Arial Black;
font-weight:normal;
-moz-border-radius:8px;
-webkit-border-radius:8px;
border-radius:8px;
border:1px solid #dcdcdc;
padding:2px 3px;
text-decoration:none;
background:-webkit-gradient( linear, left top, left bottom, color-stop(16%, #f9f9f9), color-stop(89%, #e9e9e9) );
background:-moz-linear-gradient( center top, #f9f9f9 16%, #e9e9e9 89% );
background:-ms-linear-gradient( top, #f9f9f9 16%, #e9e9e9 89% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f9f9f9', endColorstr='#e9e9e9');
background-color:#f9f9f9;
color:#666666;
display:inline-block;
text-shadow:1px 1px 0px #ffffff;
-webkit-box-shadow:inset 1px 1px 0px 0px #ffffff;
-moz-box-shadow:inset 1px 1px 0px 0px #ffffff;
box-shadow:inset 1px 1px 0px 0px #ffffff;
}.itemb1:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(16%, #e9e9e9), color-stop(89%, #f9f9f9) );
background:-moz-linear-gradient( center top, #e9e9e9 16%, #f9f9f9 89% );
background:-ms-linear-gradient( top, #e9e9e9 16%, #f9f9f9 89% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#e9e9e9', endColorstr='#f9f9f9');
background-color:#e9e9e9;
cursor:pointer;
}.itemb1:active {
position:relative;
top:1px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<section id="content" style="height:auto"><div class="ic"></div>
<div class="main" style="height:auto">
<div class="container" style="height:auto">
<table style="width: 100%;">
<tr>
<td style="width:25%"> <fieldset style="border:1px solid #808080;padding-left:2em;padding-right:1em" ><legend style="border:1px solid #808080">  Menu   </legend>
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" DataKeyNames="Groupid" DataSourceID="SqlDataSource1" EmptyDataText="Data records " OnRowCommand="GridView3_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Item Menu" SortExpression="Groupid">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Groupid") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" Text='<%# Eval("Groupname") %>' CommandName="getitem" CommandArgument='<%# Bind("Groupid") %>' runat="server" Width="250" Height="26" CssClass="itemb1" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Groupname" HeaderText="Groupname" SortExpression="Groupname" Visible="False" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:hbhbConnectionString %>" DeleteCommand="DELETE FROM [Gname] WHERE [Groupid] = @Groupid" InsertCommand="INSERT INTO [Gname] ([Groupname]) VALUES (@Groupname)" ProviderName="<%$ ConnectionStrings:hbhbConnectionString.ProviderName %>" SelectCommand="SELECT [Groupid], [Groupname] FROM [Gname]" UpdateCommand="UPDATE [Gname] SET [Groupname] = @Groupname WHERE [Groupid] = @Groupid">
<DeleteParameters>
<asp:Parameter Name="Groupid" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Groupname" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Groupname" Type="String" />
<asp:Parameter Name="Groupid" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</fieldset>
</td>
<td style="padding-left:2em;width:60%"> <fieldset style="border:1px solid #808080;padding-left:2em" ><legend style="border:1px solid #808080">  Dishes   </legend>
<asp:GridView ID="GridView4" runat="server" AutoGenerateColumns="False" DataKeyNames="Itemsid" DataSourceID="SqlDataSource2" EmptyDataText="No data" Width="612px" HeaderStyle-ForeColor="YellowGreen">
<Columns>
<asp:BoundField DataField="Itemsid" HeaderText="Itemsid" InsertVisible="False" ReadOnly="True" SortExpression="Itemsid" />
<asp:BoundField DataField="Items" HeaderText="Items" SortExpression="Items" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:HyperLinkField DataNavigateUrlFields="Itemsid" DataNavigateUrlFormatString="?ID={0}"
Text="<img src='addtocart-green.png' Height='30' alt='alternate text' border='0'/>" HeaderText="buy" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:hbhbConnectionString %>" SelectCommand="SELECT [Itemsid], [Items], [Price] FROM [items] WHERE ([Groupid] = @Groupid)">
<SelectParameters>
<asp:QueryStringParameter Name="Groupid" QueryStringField="group" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
</fieldset>
</td> </tr>
</table>
<fieldset style="border:1px solid #808080;padding-left:2em;padding-right:1em" ><legend style="border:1px solid #808080">  Checkout   </legend>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/viewcart.png" PostBackUrl="~/OrderCart.aspx" />
</fieldset>
</div>
</div>
</section>
</asp:Content>
Sir my data in gridview4 disappears when i click add to cart it shows no data again i have to pass a query from gridview 3 and then gridview 4 appears and then again if i click on add to cart in gridview 4 it shows no data