gpt4 book ai didi

c# - ASP :Label is not shown when visible is set to true?

转载 作者:太空狗 更新时间:2023-10-30 00:47:30 26 4
gpt4 key购买 nike

我有一个简单的 Web 表单,其中有几个列表框和一个搜索按钮。单击该按钮时,它会返回一个数据集。如果数据集包含记录,我将最初设置为 false 的 asp:label 设置为 true,但这并没有发生。如果数据集有记录并且visible属性设置为true,标签仍然不显示。

我也试过将标签和其他几个控件放在 html 表中,并在表上设置 runat="server"属性并更改其可见性,但两者都没有显示。

这是 aspx 代码:

<table>
<tr>
<td>
<asp:Label ID="lblSortBy" runat="server" Text="Sort By:" Visible="false">
</asp:Label>
<asp:DropDownList
ID="ddlSortBy"
runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="ddlSortBy_SelectedIndexChanged">
<asp:ListItem Value="Gross">Gross</asp:ListItem>
<asp:ListItem Value="Population">Population</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>

下面是点击按钮时的简化代码:

public void GetData()
{
DataView dv = GetReportData().DefaultView;

if(dv.ToTable().Rows.Count > 0)
{
lblSortBy.Visible = true;
}
else
{
lblSortBy.Visible = false;
}
}

我有几个围绕一些 ListBoxes 和 GridView 的更新面板,但没有 Label 和 Dropdown。这会导致问题吗?

我做了一个测试,如果找到记录并且标签消失了,我将更新面板中的标签设置为 false,所以如果它在更新面板中,它就可以工作。

最佳答案

如果我没记错的话,您的标签应该存在于更新面板上,因为就静态 HTML 页面而言,当前标签存在的唯一一次,它被设置为不可见。您必须重新加载整个页面才能使其再次可见。

关于c# - ASP :Label is not shown when visible is set to true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/534045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com