Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a shpping cart showin in gridview.. where i have shown product name , quantity , price etc.. quantitiy can b updateable..

i have also give delete fuctionality so we can delete product from shopping cart..

when the cart become empty i want to hide gridview. i also want to hide button.. and show the lable... " your have not items in your shopping cart.." my page is in ajax update panel.. all the thing are working fine.. but if i delete the product from shopping cart shown in gridview.. the product get deleted.. but i have to refreash the page to show the label having value " you have no items in your cart" and to invisible the update and the place order button..

here is the code i implemented..

C#
if (ShoppingCart.GetItems(User.Identity.Name).Count > 0)
       {
           btnupdatecart.Visible = true;
           btnplaceorder.Visible = true;
       }
             //ObjectDataSource1.DataBind();
       if (GridView1.Rows.Count == 0)
       {
           Labelinfo.Visible = true; // containing value your cart doesn't contain any item
           btnupdatecart.Visible = false;
           btnplaceorder.Visible = false;

       }
       else
       {
           Labelinfo.Visible = false;
       }


what i have to do.. that i delte th product from cart as it becomes empty. then i have no need to refresh the page. the page automatically shows the " you have no itmes in your cart"
Posted
Comments
_Tushar Patil 3-Nov-11 1:14am    
what data-source you are giving to grid-view for binding data..?
codegeekalpha 3-Nov-11 6:29am    
i am coidng manually..

Hi farooq,

I f you are using a gridview then set its empty data string so it will display the lable whenver there is no data in gridview.

I hope this helps

Thanks & regards
Sriman
 
Share this answer
 
Hi,
If ur using Updatepanel in the page when grid view row command event fire the page is mot fully rendered .

So add this code in ur Page after
<triggers>
<asp:postbacktrigger controlid="GridView1" xmlns:asp="#unknown" />  
</triggers>


and when Grid doesn't have any data Use GridView1.DataSource = String.Empty;
For Lable Control write Code Like
if(GridView1.DataSource == String.Empty || GridView1.DataSource == null)
{
   label1.Text = "Your Message";
} 


If Still u have problem Place the grid and buttons in a panel and Hide the Panel when needed.
 
Share this answer
 
v2
Comments
codegeekalpha 3-Nov-11 6:28am    
still having a same problem
Hi Just rebind your grid and after that update the update panel.


C#
this.UPDATEPANEL_ID.update();

UPDATEPANEL_ID is the id of your update panel.

Hope it works.
Thanks
Faisal
 
Share this answer
 
v2
if there are no items in your table..
to display any message
<gridview showemptyheader="true" />

make empty header to true

and then in template header field give the table column names and

in middle section display ur message
 
Share this answer
 
v2
in pageload set the visibility property for label and button as true or false as ur requirment....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900