Qayyum ChauDhary

Qayyum ChauDhary

  • NA
  • 27
  • 2.5k

How to insert an empty record (row) in asp:Repeater

Jan 8 2020 5:01 AM
How to insert one empty record after every 5 records in the repeater output?
 
Actually I need to insert one empty record after every 5 records in the repeater output.
 
For example Repeater original output is following
 
1.ABC
2.BCD
3.CDE
4.DEF
5.EFG
6.FGH
7.GHI
 
The desired output will be following
 
1.ABC
2.BCD
3.CDE
4.DEF
5.EFG
6.FGH
7.GHI
 
What i have done so far:
  1. <html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head runat="server"> <title></title> </head>  
  3. <body> <form id="form1" runat="server">  
  4. <div> <asp:Repeater ID="Repeater1" runat="server">  
  5. <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%#Eval("CustomerName") %>'></asp:Label>  
  6. <br />  
  7. </ItemTemplate>  
  8. </asp:Repeater>  
  9. </div>  
  10. </form>  
  11. </body>  
  12. </html>
and
  1. public partial class WebForm2 : System.Web.UI.Page  
  2. {  
  3. SqlConnection con = new SqlConnection();  
  4. SqlCommand cmd = new SqlCommand();  
  5. protected void Page_Load(object sender, EventArgs e)  
  6. {  
  7. con.ConnectionString = "Data Source=PC\\SQLEXPRESS;Initial Catalog=AlvisDB;Persist Security Info=True;User ID=sa;Password=pass";  
  8. con.Open();  
  9. cmd.Connection = con;  
  10. cmd.CommandText = "SELECT CustomerName FROM Customers";  
  11. SqlDataAdapter adp = new SqlDataAdapter(cmd);  
  12. DataSet ds = new DataSet();  
  13. adp.Fill(ds);  
  14. Repeater1.DataSource = ds;  
  15. Repeater1.DataBind();  
  16. con.Close();  
  17. }  
  18. }  

Answers (2)