每次刷新页面以显示标签并使按钮不可见的问题 [英] Problem to refresh the page everytime to show the label and to make buttons invisble
问题描述
我在gridview中显示了一个购物车..在这里,我显示了产品名称,数量,价格等.数量可以更新..
我也提供了删除功能,因此我们可以从购物车中删除产品.
当购物车变空时,我想隐藏gridview.我也想隐藏按钮..并显示标签...您的购物车中没有商品.."我的页面在ajax更新面板中..所有东西都工作正常..但是,如果我删除产品从gridview中显示的购物车中删除..该产品被删除..但是我必须刷新页面以显示具有值您的购物车中没有物品"的标签,并且不显示更新和下订单按钮..
这是我实现的代码.
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..
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;
}
我该怎么办..我从购物车中删除了产品,因为它变空了.那么我就不需要刷新页面了.该页面会自动显示购物车中没有Itmes".
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"
推荐答案
您好,farooq,
如果您使用的是gridview,则设置其空数据字符串,以便当gridview中没有数据时,它将显示标签.
希望对您有帮助
谢谢&问候
斯里曼(Sriman)
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
如果您在网格视图行命令事件触发时在页面中使用Updatepanel,则该页面将完全呈现.
因此,请在
后的ur Page中添加此代码
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>
并且当Grid没有任何数据时,请使用GridView1.DataSource = String.Empty;
对于标签控制,请编写类似
的代码
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.
您好 只需重新绑定网格,然后更新更新面板即可.
Hi Just rebind your grid and after that update the update panel.
this.UPDATEPANEL_ID.update();
UPDATEPANEL_ID是您的更新面板的ID.
希望它能起作用.
谢谢
费萨尔
UPDATEPANEL_ID is the id of your update panel.
Hope it works.
Thanks
Faisal
这篇关于每次刷新页面以显示标签并使按钮不可见的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!