Hi
How to get the count of rows in a repeater
Thanks
Hi
How to get the count of rows in a repeater
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh KumarRank #91 · 22.9K reputationPosted Jun 11, 2023, 11:46 PM EDT
Hello Raco,
You can do using two way,
int rowCount = myRepeater.Items.Count;OR
int rowCount = myRepeater.ItemCount;Amira BedhiafiRank #601 · 4K reputationPosted Jun 11, 2023, 8:10 AM EDT
You can access the number of items in the repeater's data source by using the
Itemsproperty and then getting the count of the collection :int rowCount = repeater1.Items.Count;
If you are manually populating the repeater control without using a data source, you can still get the count by accessing the
Itemsproperty and getting the count of the items.int rowCount = repeater1.Items.Count;
Ramco RamcoRank #462 · 5.4K reputationPosted Jun 11, 2023, 12:44 PM EDT
Hi
Do we need to subtract 1 from repeater1.Items.Count
Thanks
Prasad RaveendranRank #320 · 7.8K reputationPosted Jun 11, 2023, 9:57 PM EDT
In your ASP.NET markup file (e.g., .aspx), define a repeater control and assign it an ID:
In your code-behind file (e.g., .aspx.cs), you can access the repeater control and retrieve the row count using the
Repeater.Items.Countproperty:protected void Page_Load(object sender, EventArgs e) { // Bind data to the repeater (optional step) if (!IsPostBack) { myRepeater.DataSource = YourDataSource; // Set your data source here myRepeater.DataBind(); } // Get the row count int rowCount = myRepeater.Items.Count; // Use the row count as needed (e.g., display it to the user) YourLabel.Text = "Row count: " + rowCount.ToString(); }In this example, the Page_Load event handler is used to bind data to the repeater (if necessary) and retrieve the row count using the myRepeater.Items.Count property. You can then use the row count for further processing or display, such as assigning it to a label (YourLabel.Text) to show it to the user.
Remember to replace YourDataSource with your actual data source and adjust the item template markup according to your requirements.