开发者

C# - Displaying server control based on how many items are in a datalist

开发者 https://www.devze.com 2023-01-22 16:11 出处:网络
What I am trying to do is on page load display either of two controls 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;
0

精彩评论

暂无评论...
验证码 换一张
取 消