Click here to Skip to main content
15,896,502 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all!!

I have taken a label for showing message to the user.
I have a dropdown-list. If the Item Count of dropdown list is 0, i want to show the label to the user else not. I did the following but it's not working as expected. Can you please tell me what's wrong with this code and what should i do to get the expected result ??

XML
<asp:Label ID="lblMessage" runat="server" Text="Currently there are no products in this category" Visible='<%# bool.Parse((ddlProducts.Items.Count==0).ToString())%>' Font-Bold="true" Font-Italic="true" Font-Names="Georgea"></asp:Label>
</td>


It's always setting the label as visible whereas when the item count is not zero it should not be shown to the User.
Posted
Comments
Varun Sareen 24-Feb-12 3:20am    
show us the code where you are binding the data to the dropdownlist.. I guess you are adding an item at index 0 of the dropdown like:- "-Select-".
ujjwal uniyal 24-Feb-12 3:29am    
private void fillList()
{
SqlCommand cmdpopulate1 = new SqlCommand("Select PName,PID from Products where PCategoryID='" + Request.QueryString["id"] + "'", con);
SqlDataAdapter da1 = new SqlDataAdapter(cmdpopulate1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
ddlProducts.DataSource = ds1;
ddlProducts.DataTextField = "PName";
ddlProducts.DataValueField = "PID";
ddlProducts.DataBind();
con.Close();
}

I am calling this function on pageload
Sudip Saha 24-Feb-12 4:43am    
CDo the view source of the page when it is running
and check what is the value is set with Visible attribute

Visible='<%# bool.Parse((ddlProducts.Items.Count==0).ToString())%>'
Varun Sareen 24-Feb-12 4:46am    
good, we actually have to know about the value.

1 solution

i think its better if u check it on page load where u required it as,
if(ddlProducts.Item.Count == 0)
{
lblMessage.visible = true;
}
and keep its visible property in aspx syntax visible="false". i think this may solve your problem.
 
Share this answer
 
Comments
ujjwal uniyal 24-Feb-12 5:13am    
I can do that from the pageload event but i was trying to do it from the source of the page.....

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