I have a simple web form that has several lists and a search button. When a button is pressed, it returns a DataSet. If the data set contains records, I set the asp: label, which is initially set to false, to true, but this does not happen. If there are records in the dataset and the visible property is set to true, the label is still not displayed.
I also tried putting a shortcut and a couple of other controls in the html table and setting the runat = "server" attribute in the table and changing the visibility of this, but it also does not appear.
Here is the aspx code:
<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>
The following is a simplified code when a button is clicked:
public void GetData() { DataView dv = GetReportData().DefaultView; if(dv.ToTable().Rows.Count > 0) { lblSortBy.Visible = true; } else { lblSortBy.Visible = false; } }
I have a couple of update panels around some ListBoxes and GridView, but not Label and Dropdown. Will this cause a problem?
I did a test, I set the label that was in the update panel to false if the entries were found and the label disappeared, so it works if it is in the update panel.
source share