开发者

Using mod operator in C#

Items开发者_Python百科:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18


Repeater control I want to place class on highlighted item number.

so ... I have done following code.

if ((DL_NewProducts.Items.Count) % 3 == 0)
{
    var libox = e.Item.FindControl("libox") as HtmlGenericControl;
    if (libox != null)
        libox.Attributes["class"] = "last";
}

Here is problem that in first iteration it find three items, mod work fine and it place class on 4th item but in second iteration it come again on 6th item and place class on 7th item while I want it to place it on 8th what will be correct logic for it..


You are looking for (DL_NewProducts.Items.Count % 4) == 0.


The question isn't completely clear - you have marked the sequence 4, 8, 12, ... in bold but appear to actually want the numbers in the sequence 3, 7, 11... to pass the test.

So I think you're looking for the expression:

DL_NewProducts.Items.Count % 4 == 3

But it's hard to tell since it isn't clear if those numbers at the top represent counts, zero-based indices or one-based indices. If you can clarify exactly what they represent and how they relate to the collection's count, we might be able to provide more appropriate answers.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜