Change repeater li item class if first or last

前端 未结 10 2133
时光说笑
时光说笑 2020-12-05 07:11

I\'m using repeater to create dynamic ul li list

Is it possible to control class whether item is first or last?

Something like:

class=\"<%         


        
10条回答
  •  一整个雨季
    2020-12-05 07:37

    If your are using controls within your ItemTemplate you can do something like the following, add OnItemDataBound event.

    
      
        
          <%#Eval("Content") %>
        
      
    
    
    protected void OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemIndex == 0)
          ((Panel) e.Item.FindControl("PnlCtrlItem")).CssClass = "first";
        //or the following to have your control indexed
        ((Panel) e.Item.FindControl("PnlCtrlItem")).CssClass = string.Format("item-{0}",e.Item.ItemIndex);
    }
    

提交回复
热议问题