ASP.NET - Which control can i use to display each item details in online shopping

Asked By Dreamguyster ng on 15-Jun-12 10:24 AM
Hi,

I have made 2 section, 1 for search the product and items and another is to display resulted items.
Now I want to display resulted items in other section of same page like http://www.shopper.com.my/.

How can I disply each items separated and when he click buy button against each item i want to bring register page.

Whether Gridview control may help to build this appn ??

I have already designed the page but confused how to display items

I am using asp.net 2.0


Thanks,
Dreamguy
dipa ahuja replied to Dreamguyster ng on 16-Jun-12 05:29 PM
You are right. You should use the gridview for shopping cart.

I can give you the basin info about the shopping cart project


1. Decide how many tables you will required
2. Decide the relationships between those tables
3. Choose proper template for your website
4. Choose no. of WebPages you will need ,and navigation from one page to another..

Now the real cart process:

For Shopping Cart you have two options, Either you can use the shopping card which is available with ready made functionality or create your own cart process:
Now what you have to do is:
Put a page like items, in items page put all the categories of items, for ex if you are making of electronic shop then product categories will be Television, dvd player, telephones, Home theatres etc..

Now use will select an item - > he will be redirected to the ItemDescription page where user will get more info about that particular item
Suppose you are displaying your item in the page "item.aspx"
now put one button "Add To Cart" iand when user clicks on it.. add the selected item into tmp table with the fields like itemname, price,userId/userName etc...
now suppose you have page cart.aspx.. here you can take gridview and bind it with the "tmp" table with the items that user has selected .

so the query of gridview will be "Select itemName,Price from tmp where username=<currentlyLoginUSer>"..

start this way.. you will get more idea when you code this....
 
 

Vikram Singh Saini replied to Dreamguyster ng on 16-Jun-12 08:45 PM
I have made 2 section, 1 for search the product and items and another is to display resulted items.
Now I want to display resulted items in other section of same page like http://www.shopper.com.my/.

For creating two sections you can use panels in same page. One for searching the product and another for display resulted items. The resulted items can be displayed in gridview. You can use customized template fields for your requirements.

How can I disply each items separated and when he click buy button against each item i want to bring register page.

Declare code as follow in .aspx:

<asp:GridView ID="products" runat="server">

      <Columns>

        <asp:TemplateField>

          <ItemTemplate>

            <div style="border: 1px solid black">

              <div class="leftCol">

                <asp:Image ID="prodImage" runat="server" />

              </div>

              <div class="rightCol">

                <asp:Label ID="lblProdName" runat="server" />

                <asp:Label ID="lblDetails" runat="server" />

                <asp:Button ID="btnBuy" runat="server" Text="buy" OnClick="btnBuy_Click" />

              </div>

            </div>

          </ItemTemplate>

        </asp:TemplateField>

      </Columns>

    </asp:GridView>


And handle the button click code as:

protected void btnBuy_Click(object sender, EventArgs e)

    {

      // Check if the user has already logged in

 

      // If yes, then don't show user register page

      // else redirect user to register page

    }


Hope this helps. Ask for assistance if any doubts.
Dreamguyster ng replied to Vikram Singh Saini on 17-Jun-12 05:59 AM
Thanks I implemented the way you said.I had 2 div and one for search and other for items display.
Now when i display items in gridview itemtemplate I am binding suppid and requestid to hiddenfield.

When click one perticular items it displays DIV popup where he enters the details to save.
Now how can I retrieve these suppid and requestid of selected item from gridview.
Divpop up happens when i click img button from clientside.

Just want to retrive the selected items hiddenfield value so based on that i can save the record


thanks
Vikram Singh Saini replied to Dreamguyster ng on 17-Jun-12 02:32 PM
Write following code in the button's onclick server event handler. Code here:

GridViewRow gvr = GridView1.SelectedRow;

 

      // Find controls in selected gridivew row

      HiddenField hfSuppID = gvr.FindControl("hfSuppId") as HiddenField;

      HiddenField hfRequestID = gvr.FindControl("hfRequestId") as HiddenField;

 

      if (hfSuppID != null && hfRequestID != null)

      {

        string supp = hfSuppID.Value;

        string req = hfRequestID.Value;

 

        // Now save the record by values retrieved

      }


The code is itself self understood. If any doubt, let us know.
Vikram Singh Saini replied to Dreamguyster ng on 17-Jun-12 10:37 PM
When click one perticular items it displays DIV popup where he enters the details to save.
Now how can I retrieve these suppid and requestid of selected item from gridview.
Divpop up happens when i click img button from clientside.


I would try following steps for achieving objective as:

1. Declare gridview with select command field as: (code snippet only)

<asp:CommandField ShowSelectButton="true" ButtonType="Image" SelectImageUrl="~/Images/buy.png" /> 


2.  Declare onselected index changed for gridview. Declare same in .aspx as:


<
asp:GridView ID="gridNumbers" runat="server" AutoGenerateColumns="false"        OnSelectedIndexChanged="gridNumbers_SelectedIndexChanged">

        <SelectedRowStyle BackColor="Orange" />
        <Columns>         

          <asp:TemplateField ItemStyle-HorizontalAlign="Center">

            <ItemTemplate>

              <asp:HiddenField ID="hfSuppId" runat="server" Value="Supplier" />

              <asp:HiddenField ID="hfRequestId" runat="server" Value="Product" />

            </ItemTemplate>

          </asp:TemplateField>  

          <asp:CommandField ShowSelectButton="true" ButtonType="Image" SelectImageUrl="~/Images/vcard.png" />

        </Columns>

      </asp:GridView>

      <asp:Label ID="lblHfValue" runat="server" />


and in .aspx.cs

protected void gridNumbers_SelectedIndexChanged(object sender, EventArgs e)

    {

      GridViewRow gvr = (sender as GridView).SelectedRow;

 

      // Find controls in selected gridivew row

      HiddenField hfSuppID = gvr.FindControl("hfSuppId") as HiddenField;

      HiddenField hfRequestID = gvr.FindControl("hfRequestId") as HiddenField;

 

      if (hfSuppID != null && hfRequestID != null)

      {

        string supp = hfSuppID.Value;

        string req = hfRequestID.Value;      

 

        // Now save the record by values retrieved
// I am showing the retrieved values in the Label field here

        lblHfValue.Text = "Received values: " + supp + " and " + req;

      }

 

    }

 
The code has been tested and is working fine.

Jitendra Faye replied to Dreamguyster ng on 18-Jun-12 12:55 AM
Yes, You told that first you want to display item then for This DataList or repeater control will be suitable.

If you are using DataList then you can display item horizontally or vertically.

Now as you told that for each item you want to display Registration page  then For this you can use ImageButton.

means you can display image and redirect to registration page also using ImageButtom.

Like this-

<ItemTemplate>
      <asp:ImageButton ID="Im" runat="server" ImageUrl='<%# "Handler1.ashx?EmpId=" + Eval("Empid")%>' PostBackUrl="Registration.aspx" />
  </ItemTemplate>




Trey like this and let me know.