# Total Count divided range calculation in c# • ### Question

• User689180510 posted

Hi,

I have a task ,which if records contains more than 299, i need to pass the value 299 for each call to the backend

eg : Total Rows = 1000, i need to send each call as 299 i,e(0-299, 300-599, 600-899 ......)

Coding:

output :  response. totalrows = 1000;

///  how to write a condition/calculation here

return response ; //after that i need to add all the Readdata statement output and bind in final response .

Wednesday, December 19, 2018 9:14 AM

• User-893317190 posted

Hi jafferpg,

According to your description, do you want 299 when the record is in 300-599 ,want 599 when record is in 600-899 , want 899 when record is in 900-1199?

If so , you could try the code below.To show the range , I use the method DivideRecords, you could only use the method GetResult.

```  protected void Page_Load(object sender, EventArgs e)
{
Response.Write(DivideRecords(1000)+";"+"result:"+GetResult(1000));
}
static double GetResult(int number)
{
double count = Math.Ceiling((number+1) * 1.0 / 300); //get how many 300 there are in the number
return (count - 1) * 300 - 1; //get the final result according to  how many 300 there are in the number
}
static string DivideRecords(int number)
{
string result = "";
double count = Math.Ceiling(number * 1.0 / 300);
for (int i = 0; i < count-1; i++)
{
string temp = i * 300 + "-" + ((i + 1) * 300 - 1)+",";
result += temp;
}
result += (count - 1) * 300 + "-" + (number-1);
return result;
}```

Below is the result. Best regards,

Ackerly Xu

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Thursday, December 20, 2018 2:39 AM
• User689180510 posted

I done by using the below method

if (response.TotalCountRows > 299)
{
for (int i = 300; i <= response.TotalCountRows; i++)
{
search.firstvalue = i;
if ((i + 299) <= response.TotalCountRows)
search.lastvalue = i + 299;
else
search.lastvalue = Convert.ToInt32(response.TotalCountRows);

SplitData(search, messageID, response);

i = i + 299;
}
}

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Thursday, December 20, 2018 8:53 AM

### All replies

• User-893317190 posted

Hi jafferpg,

According to your description, do you want 299 when the record is in 300-599 ,want 599 when record is in 600-899 , want 899 when record is in 900-1199?

If so , you could try the code below.To show the range , I use the method DivideRecords, you could only use the method GetResult.

```  protected void Page_Load(object sender, EventArgs e)
{
Response.Write(DivideRecords(1000)+";"+"result:"+GetResult(1000));
}
static double GetResult(int number)
{
double count = Math.Ceiling((number+1) * 1.0 / 300); //get how many 300 there are in the number
return (count - 1) * 300 - 1; //get the final result according to  how many 300 there are in the number
}
static string DivideRecords(int number)
{
string result = "";
double count = Math.Ceiling(number * 1.0 / 300);
for (int i = 0; i < count-1; i++)
{
string temp = i * 300 + "-" + ((i + 1) * 300 - 1)+",";
result += temp;
}
result += (count - 1) * 300 + "-" + (number-1);
return result;
}```

Below is the result. Best regards,

Ackerly Xu

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Thursday, December 20, 2018 2:39 AM
• User689180510 posted

I done by using the below method

if (response.TotalCountRows > 299)
{
for (int i = 300; i <= response.TotalCountRows; i++)
{
search.firstvalue = i;
if ((i + 299) <= response.TotalCountRows)
search.lastvalue = i + 299;
else
search.lastvalue = Convert.ToInt32(response.TotalCountRows);

SplitData(search, messageID, response);

i = i + 299;
}
}

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Thursday, December 20, 2018 8:53 AM