Default text for empty Repeater control

前端 未结 8 982
醉梦人生
醉梦人生 2021-02-02 05:43

Using VS 2008, I have a Repeater control:



        
8条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 06:30

    The best way I found to solve this :

    1. Add the following label anywhere on your page -

      
      
    2. Add the OnPreRenderEvent for your Repeater

      
      
    3. Now inside this event in your codebehind, write the code

      protected void emptyRepeater_PreRender(object sender, EventArgs e)
      {
         lblEmptyRepeater.Visible = (emptyRepeater.Items.Count==0);
      }
      
    4. Now your empty repeater should be checked after the data is bound but before render on page, and show the label if it is empty.

提交回复
热议问题