设计:
如果我没有添加任何土地成分价格/航班价格,我希望系统处理未使用的控制并向上移动以填补空白区域,但不知何故,或者更确切地说,它变成了这样。< / p>
结果:
if (bf.landComponent != 0.00m)
{
lblLandComponent.Text = "" + bf.landComponent;
lblLandComponent.Visible = true;
lblLandComponentL.Visible = true;
}
else
{
lblLandComponent.Dispose();
lblLandComponentL.Dispose();
}
if (bf.flightComponent != 0.00m)
{
lblFlightComponent.Text = "" + bf.flightComponent;
lblFlightComponent.Visible = true;
lblFlightComponentL.Visible = true;
}
if (bf.unitSales != 0.00m)
{
lblUnitSales.Text = "" + bf.unitSales;
lblUnitSales.Visible = true;
lblUnitSalesL.Visible = true;
}
if(bf.rentalCar!=0.00m)
{
lblCT.Visible = true;
lblRentalCar_L.Visible = true;
lblRentalCar.Visible = true;
lblRentalCar.Text = "" + bf.rentalCar;
}
if (bf.discount != 0.00m)
{
lblDiscount.Text = "" + bf.discount;
lblDiscountL.Visible = true;
lblDiscount.Visible = true;
}
if(bf.packageInclusion!="")
{
lblPackageInclusion.Text = bf.packageInclusion;
lblPackageInclusion.Visible = true;
lblPackageInclusionL.Visible = true;
}
//BF is a class object stored in a session that i put from the previous page.
有什么不对吗?
答案 0 :(得分:0)
Dispose
方法不适用于您想要的内容。检查文档,看看它到底发生了什么。
如果要隐藏控件,请尝试将其可见性设置为false
,或尝试将其从父容器控件中删除。
有条件地将Visibility
设置为true
是不够的。在99%的情况下,无论如何它们都是可见的,因为它是可见性的默认值。您必须确保将其初始可见性设置为false,或者添加将执行此操作的else子句。