C# - Displaying server control based on how many items are in a datalist
What I am trying to do is on page load display either of two controls based on how many items are in a datalist.
For instance, if the datalist only contains 1 item I want it to display
Literal1.Visible = true;
If there is more than 1 item in the datalist, then show
LiteralMulti.Visible 开发者_高级运维= true;
Anyone know how to do this?
Use can simple do that in Page_Load method :
if(DataListName.Items.Count > 1)
{
Literalmulti.Visible = true;
}
else
{
Literalsingle.Visible = true;
}
Check the Count of the Items property.
Literal1.Visible = myDataList.Items.Count == 1;
LiteralMulti.Visible = myDataList.Items.Count > 1;
精彩评论